HOME

Tuesday, February 14, 2012

Why Compute clause in Sql Server ?

Generates totals that appear as additional summary columns at the end of the result set. When used with BY, the COMPUTE clause generates control-breaks and subtotals in the result set.

USE Database;
GO
SELECT CustomerID, OrderDate, SubTotal, TotalDue
FROM Sales.SalesOrderHeader
WHERE ID = 1
ORDER BY OrderDate
COMPUTE SUM(SubTotal), SUM(TotalDue);

2 comments:

  1. how do you access in c#?

    ReplyDelete
    Replies
    1. for this query it will return two table ...
      first table contains all data CustomerID, OrderDate, SubTotal, TotalDue....
      second table contains total sums of SubTotal and TotalDue

      means first table u can directly bind to your grid
      second table's two sums can you put in footer row as sums of respective columns...
      Ex:---
      griedview.datasource=ds.table[0];
      griedview.databind();

      griedview.HeaderRow.cell[2].text= ds.table[1].rows[0]0].tostring();

      griedview.HeaderRow.cell[3].text= ds.table[1].rows[0]1].tostring();

      Delete