Click here to Skip to main content
13,799,002 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 31 Aug 2011
Licenced CPOL

Query for running total in SQL Server

, 4 Sep 2011
This will work on SQL 2000/2005/2008.Most cumulative aggregations have constraints such as a begin and end date or grouped by customers.Your solution is good for a single aggregation without much filtering. People will find that the query plans generated would be very similiar to that of...


Members may post updates or alternatives to this current article in order to show different approaches or add new features.

25 Aug 2011
I guess this is more faster:SELECT T1.Field1, SUM(T2.Field1) FROM [Table] T1, [Table] T2WHERE T1.Field1 >= T2.Field1GROUP BY T1.Field1
24 Aug 2011
Elina Blank
Using window functions (partition by) will speed up the process:SELECT Val, SUM(Val) OVER (Partition BY [YourPartitionValue] Order BY [OrderColumn] as CumulativeSumFROM [Table]
31 Aug 2011
Mukit, Ataul
4 alternatives  
Calculate running total or cumulative sum from a table in a SQL Server database.
26 Aug 2011
S Douglas
Another way of getting totals, whether it be by group or set is to use the CUBE and ROLLUP predicates.By group (each grouping of FIELD_DESCRIPTION will have a total sum):SELECT FIELD_DESCRIPTION , SUM(FIELD_VALUE)FROM tbl_DataGROUP BY FIELD_DESCRIPTIONWITH CUBEOr:By Cube...


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


About the Author

United States United States
No Biography provided

| | Privacy | Cookies | Terms of Use | Mobile
Web02 | 2.8.181207.3 | Last Updated 4 Sep 2011
Article Copyright 2011 by fordc03
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid