Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / database / SQL-Server

Query for running total in SQL Server

4.00/5 (1 vote)
24 Aug 2011CPOL 12K  
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:
SQL
SELECT Val, 
SUM(Val) OVER (Partition BY [YourPartitionValue] 
                  Order BY [OrderColumn] as CumulativeSum
FROM [Table]

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)