Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 statement from table values

Author  Topic 

pnpsql
Posting Yak Master

246 Posts

Posted - 2012-07-10 : 06:50:47
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
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-07-10 : 07:06:07
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

246 Posts

Posted - 2012-07-10 : 07:29:08
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

52326 Posts

Posted - 2012-07-10 : 10:24:50
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
   

- Advertisement -