snippetsqlMajor
How to Get the Sum (total) of a column in a query result set
Viewed 0 times
totalresultthehowcolumnquerygetsumset
Problem
Is there a way that I can get the sum of a column in my query result set by just clicking on the column (something like in Excel) so that I don't have to copy and paste the column into Excel to the see the total sum of all the values in the column?
I'm running SQL Server 2008.
I'm running SQL Server 2008.
Solution
Use the OVER clause to modify a SUM scope in your query. No GROUP BY needed
Otherwise, SSMS isn't a calculating engine: it display query results so add it to your query...
SELECT
MyColumn, OtherColumn,
SUM(MyColumn) OVER () AS SumTotal
FROM
...Otherwise, SSMS isn't a calculating engine: it display query results so add it to your query...
Code Snippets
SELECT
MyColumn, OtherColumn,
SUM(MyColumn) OVER () AS SumTotal
FROM
...Context
StackExchange Database Administrators Q#14906, answer score: 30
Revisions (0)
No revisions yet.