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)
 update query

Author  Topic 

acdacd
Yak Posting Veteran

63 Posts

Posted - 2005-08-23 : 03:02:44
TableA
ItemID Value
1........ 1
2........ 2
3.........3
4.........4

For example, if i want to update the value by adding all previous value and itself that is order by itemid

Result
1........1
2........3
3........6
4........10

Any way to do it in update query?

be a hardworking people!!

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-23 : 03:13:18
I think no need to update just use this select query

Select ItemId,(Select sum(value) from TableA where ItemId<=T.ItemId) from TableA T

Madhivanan

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

acdacd
Yak Posting Veteran

63 Posts

Posted - 2005-08-23 : 03:18:45
OIC. But this is only select statement.

Can i directly use it result to update the table, i mean i worry that the during it sum process, some value will overwrite other value so the result is not correct

Of course, it is not a practical use but only interesting q for me!

be a hardworking people!!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-23 : 03:28:01
It seems that it is only a presentation issue and I dont think there is need for updation

Madhivanan

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

mmarovic
Aged Yak Warrior

518 Posts

Posted - 2005-08-23 : 10:47:40
If you really want it, here it is:
declare @value int
set @value = 0
update tableA
set @value = value = value + @value
Go to Top of Page
   

- Advertisement -