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 2008 Forums
 Transact-SQL (2008)
 cumulative

Author  Topic 

inbs
Aged Yak Warrior

860 Posts

Posted - 2012-10-22 : 11:43:08
[code]
Qunt Date Classify Cumulative RowNo
50 17.06 S 50 1
100 22.06 R 50 2
20 24.06 S 70 3
[/code]

i have cumulative table, but i have some logic buisness here,
1.how can cumulative just rows ,that
cumulative of row 1 (50) is lower than Qnt of row 2, so i put
the last qnt in cumulative in row 2
2.in row 3 the qnt 20 is lower than 50 so i added 50+20.

any help
thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-10-22 : 12:11:26
do you mean this?

UPDATE t
SET t.Cumulative= CASE WHEN t.Qunt > t1.Cumulative THEN t1.Qunt ELSE t1.Cumulative + t.Qunt END
FROM table t
INNER JOIN table t1
On t1.RowNo = t.RowNo-1


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

Go to Top of Page

inbs
Aged Yak Warrior

860 Posts

Posted - 2012-10-22 : 14:16:11
but i do not have RowNo column,this was for the example
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-10-22 : 14:39:37
then what determines your sequence? is there a datetime column? otherwise you cant guarantee order of rerieval

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

Go to Top of Page
   

- Advertisement -