Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
i have created a schedule in excel like below there is formula in no col like : prin * rate / 80; and in bal column from second row : bal - noprin 100 rate 18 id no bal1 22.5 1002 22.5 77.53 22.5 554 22.5 32.55 22.5 106 22.5 -12.57 22.5 -35after that i need to do that take a value in rate field that leads the bal column last row value to 0.00 and for the same i use goal seek in excel. and the result is shown below . prin 100 rate 13.33333333 id no bal1 16.66666667 1002 16.66666667 83.333333333 16.66666667 66.666666674 16.66666667 505 16.66666667 33.333333336 16.66666667 16.666666677 16.66666667 0.00but now i use to do the same in tsql. pls help challenge everything
nathans
Aged Yak Warrior
938 Posts
Posted - 2012-07-08 : 12:53:20
How about
declare @prin decimal(10,2) = 100, @rate decimal(10,8) = 18.0--13.33333333 ;with numbers (n)--replace with your num tableas ( select n from (values(1),(2),(3),(4),(5),(6),(7))v(n) )select [Id] = n, [no] = (@prin*@rate)/80.0, [bal] = @prin - ((@prin*@rate)*(n-1))/80.0from numbers
Nathan Skerl
pnpsql
Posting Yak Master
246 Posts
Posted - 2012-07-09 : 01:39:32
i need to pass number of rows that should be deisplayed and last row should be 0.00 and according to that the @rate need to change.challenge everything
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2012-07-09 : 09:52:21
hmm...do you mean to say @rate is not an input? so what all user will input as values?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
nathans
Aged Yak Warrior
938 Posts
Posted - 2012-07-09 : 13:50:06
Yes, I thought prin and rate were your inputs. If you would also like to input the "number of rows" just use it to limit the numbers table, ie:
...from numberswhere n <= @NumberOfRows
pnpsql
Posting Yak Master
246 Posts
Posted - 2012-07-10 : 00:35:15
the int rate, prin and no of rows are inputs but the intrate should change when we set last row as o.oo.challenge everything