Reputation:
Is it possible to get column wise total using query? in my grid there are 20 columns. i have to display each columns total value in its footer. now im using TemplateField field and javascript function to get the total value.if it is possible to get it from sql query i can reduce the code
Upvotes: 2
Views: 4101
Reputation: 15849
To sum columns, it's best to use whatever client you're dealing with (Reporting Services, Datagrid, whatever), and just tell that to display a totals row.
If you were to do it within the same query, then you'd end up with rows that meant something different, and displaying it becomes quite awkward.
You CAN do it in the query, but you probably shouldn't.
Rob
Upvotes: 1
Reputation: 15849
Try something like:
SELECT *, SUM(SalesAmount) OVER() as TotalSales
FROM YourTable
But if you only need the sum and nothing else, just do:
SELECT SUM(SalesAmount) as TotalSales
FROM YourTable
And in future, please try to give more information in your question.
Rob
Upvotes: 2
Reputation: 187110
I think you are looking for SUM function
Eg:
SELECT SUM(salary) as "Total Salary"
FROM employees
Upvotes: 0