tags:

views:

1087

answers:

3

Hi All,

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

A: 

I think you are looking for SUM function

Eg:

SELECT SUM(salary) as "Total Salary"
FROM employees
rahul
+1  A: 

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

Rob Farley
sorry... 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..
+1  A: 

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

Rob Farley
Ok thanku i ll try to find that option