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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 sum all the way.....

Author  Topic 

mangyun
Starting Member

8 Posts

Posted - 2007-12-07 : 03:43:48
-- sorry, didn't search the forum befor. got it already. thanks.

table 1
aaa bbb c
001 abc 1
002 abc 2
003 abc 3
004 abc 4

table 2
aaa bbb c dd
001 abc 1 1
002 abc 2 3
003 abc 3 6
004 abc 4 10


How can I create the second table, without loop ?

The last column(dd) = previous (dd )+ current (c)
ex. last record -> 10 = 6 + 4

Thanks

Mangyun


khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-12-07 : 03:50:50
[code]select, aaa, bbb, c,
dd = (select sum(c) from table1 x where x.aaa <= t.aaa)
from table1 t[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

mangyun
Starting Member

8 Posts

Posted - 2007-12-07 : 04:04:20
thanks KH. such a quick response.
Problem solved thanks 2 U.

Mangyun
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-07 : 05:56:36

Alternatively, if you use front end application, you can do the same there using while loop

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -