65.9K
CodeProject is changing. Read more.
Home

Query for running total in SQL Server

starIconstarIconstarIconstarIconemptyStarIcon

4.00/5 (1 vote)

Aug 24, 2011

CPOL
viewsIcon

12010

Using window functions (partition by) will speed up the process:SELECT Val, SUM(Val) OVER (Partition BY [YourPartitionValue] Order BY [OrderColumn] as CumulativeSumFROM [Table]

Using window functions (partition by) will speed up the process:
SELECT Val, 
SUM(Val) OVER (Partition BY [YourPartitionValue] 
                  Order BY [OrderColumn] as CumulativeSum
FROM [Table]