Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Running Totals
Message
 
General information
Forum:
Microsoft SQL Server
Category:
Other
Title:
Miscellaneous
Thread ID:
01422486
Message ID:
01422542
Views:
46
This message has been marked as a message which has helped to the initial question of the thread.
>>LOL.. I can't use CTEs.. lol. I wish!
>
>Why you can not use CTE? What version of SQL Server you're using?
>
>Alternative solution would be to use either temp table or table variable.

CTE solution by Nikola
Declare @t table (id int identity, value int)
Insert into @t(value)
Select 120 union all
Select  60 union all
Select 125 union all
Select  40 union all
Select  10 union all
Select  25 union all
Select  40 union all
Select  55 union all
Select  70 union all
Select  85 union all
Select 100 union all
Select 115 union all
Select 130 union all
Select 145 union all
Select 160 union all
Select 175 union all
Select 190 union all
Select 205

;With a as
(
Select 1        as id,
      t1.value as value,
      t1.value as total
 From @t t1 Where id=1
Union All
Select t2.id    as id,
      t2.value as value,
      a.total+t2.value as total
 From a
 Inner Join @t t2 on a.id+1=t2.id
 Where t2.id is not null
)
Select id, Value, total
 from a
 Order by id
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform