65.9K
CodeProject is changing. Read more.
Home

Query for running total in SQL Server

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.33/5 (6 votes)

Feb 14, 2011

CPOL
viewsIcon

58201

Calculate running total or cumulative sum from a table in a SQL Server database.

SELECT Field1, (SELECT SUM(Field1) FROM [Table] WHERE Field1 <= t.Field1) AS CumulativeSum
 FROM [Table] AS t