10

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.

0

2 Answers 2

30

Use the OVER clause to modify a SUM scope in your query. No GROUP BY needed

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...

1
  • @gbn Thanks! I just tried it and it worked. Beats having to switch over to excel and copying and pasting columns. The fact that I don't have to group by all the other columns is the best part.
    – Juan Velez
    Mar 13, 2012 at 20:15
2

You can use GROUP BY and SUM of particular column value.

SELECT EmployeeName, SUM(Salary)
  FROM YourTable
  GROUP BY EmployeeName

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.