Calculate a Running Total in SQL Server
The easiest and most efficient way in modern SQL Server is to use a window function with SUM() OVER(). For example:SELECT OrderDate, Amount, SUM(Amount) OVER ( ORDER BY OrderDate ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) AS RunningTotalFROM SalesORDER BY OrderDate;This calculates the cumulative total from the…
Answered Jul 30, 2026 · 690 Views Read answer →