SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 statement from table values
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

pnpsql
Posting Yak Master

India
241 Posts

Posted - 07/10/2012 :  06:50:47  Show Profile  Reply with Quote
i have a table tbl_rate
like below on basis of values in
tbl_rate following statements need to derived.


no rate
1 18
6 19

the rate of 18% is applied from no 1 to 3 and 19% is applied from
6 till end.


no rate
1 18
4 19
7 20

the rate of 18% is applied from no 1 to 3 , 19% is applied from
no 4 to 6 and 20% is applied from 7 till end.

challenge everything

sunitabeck
Flowing Fount of Yak Knowledge

5152 Posts

Posted - 07/10/2012 :  07:06:07  Show Profile  Reply with Quote
Are you trying to populate a table with a range of values, or just trying to get the rate if you are given a value? In the latter case, you can do the following:
DECLARE @no INT;
SET @no = 13;

SELECT TOP (1)
	no,rate
FROM
	tbl_rate
WHERE
	no <= @no
ORDER BY
	no
If you are trying to populate a table with a range of values, you can apply a similar logic, except you would need a table of numbers.
Go to Top of Page

pnpsql
Posting Yak Master

India
241 Posts

Posted - 07/10/2012 :  07:29:08  Show Profile  Reply with Quote
i need to create a statement on the basis of table values . and it depends on no of rows of table.

no rate
1 18
6 19


when two rows then
the rate of 18% is applied from no 1 to 3 and 19% is applied from
6 till end.




when 3 rows


no rate
1 18
4 19
7 20
then
the rate of 18% is applied from no 1 to 3 , 19% is applied from
no 4 to 6 and 20% is applied from 7 till end.



challenge everything
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47023 Posts

Posted - 07/10/2012 :  10:24:50  Show Profile  Reply with Quote
over what field you want rate to be applied? i cant see any other fields barring id and rate in above sample data

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000