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
 addiing rows consecutively

Author  Topic 

shilpash
Posting Yak Master

103 Posts

Posted - 2012-07-01 : 16:53:51

Id Value Expected values
1 100 100
2 200 300
3 200 500
4 500 1000
5 300 1300

I need a new column(Expected Values) this is how i got..100,100+200,200+200+100,500+200+200+100,300+500+200+200+100
adding consecutively rows..

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-01 : 17:15:20
[code]
SELECT *
FROM table t
CROSS APPLY (SELECT SUM(Value) AS ExpectedValue
FROM table
WHERE Id < = t.Id
)t1
[/code]

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

Go to Top of Page
   

- Advertisement -