6

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.

20

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

  • @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 '12 at 20:15
1

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, privacy policy and cookie policy

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