You can do this - but not sure this technique (quirky update as some call it) will guarantee the order of the updates unless this table is a permanent table with clustered index.EDIT:Here are a couple discussions about it with another poster(Jeff Moden). Also, I think he wrote an article about it on sqlservercentral.comhttp://www.sqlteam.com/forums/topic.asp?TOPIC_ID=93431http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=93091&whichpage=2DECLARE @SalesTbl TABLE (custid smallint, ordermonth datetime, qty int, runqty int)DECLARE @runQTY int declare @prevCustid intINSERT INTO @SalesTblselect 1, 1,10, null union allselect 1, 1,12, null union allselect 2, 1,13, null union allselect 2, 2,10, null union allselect 3, 2,12, null union allselect 3, 2,13, null union allselect 3, 2,10, null union allselect 4, 2,12, null union allselect 4, 2,13, null UPdate @SalesTbl set @runqty = Runqty = case when custid = @prevCustid then @Runqty + qty else qty end ,@prevCustid = custid Select * from @SalesTblOUTPUT:custid ordermonth qty runqty------ ----------------------- ----------- -----------1 1900-01-02 00:00:00.000 10 101 1900-01-02 00:00:00.000 12 222 1900-01-02 00:00:00.000 13 132 1900-01-03 00:00:00.000 10 233 1900-01-03 00:00:00.000 12 123 1900-01-03 00:00:00.000 13 253 1900-01-03 00:00:00.000 10 354 1900-01-03 00:00:00.000 12 124 1900-01-03 00:00:00.000 13 25
Be One with the OptimizerTG