August 12, 2011 at 11:23 am
90 | 90-20=70 | 70-60=10 | 10-05=05
50 | 50-10=10 | 10-00=10 | 10-08=02
00 | 00-00=00 | 00-00=00 | 00-00=00
20 | 20-05=00 | 15-10=05 | 05-05=00
* first column is the initial value to subtract
* subtracting the other columns are according to the previous
August 12, 2011 at 11:24 am
Can you explain a lot more what you're after? Read this to see the best way to post this to get quick responses.
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
August 12, 2011 at 11:42 am
Just a swag at what you are after...
create table #Nums
(
col1 int,
col2 int,
col3 int,
col4 int
)
insert #Nums (col1, col2, col3, col4)
values
(90, 20, 60, 5),
(50, 10, 0, 8),
(0, 0, 0, 0),
(20, 5, 10, 5)
select col1, col1 - col2, col1 - col2 - col3, col1 - col2 - col3 - col4
from #Nums
This seems like it might be what you are after, at least it works with one of your examples.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
August 12, 2011 at 3:46 pm
The first one looks like a running total. But I can't make any sense of the other rows.
Neither (50-10 = 10) nor (20-5=5 ) compute for me.
__________________________________________________
Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply