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

3.33/5 (6 votes)
31 Aug 2011CPOL 58.2K  
Calculate running total or cumulative sum from a table in a SQL Server database.
SQL
SELECT Field1, (SELECT SUM(Field1) FROM [Table] WHERE Field1 <= t.Field1) AS CumulativeSum
 FROM [Table] AS t

License

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