Question : SQL subtotal, grand total by group

Using MS Access sql to query a Pervasive sql databsase and getting the correct info, however I am having a little trouble getting to the next step. SQL being used:
SELECT ARCustomer.Name, ARInvoice.InvoiceDate, ARInvoice.InvoiceNo, ARInvoice.Subtotal, ARInvoice.FreightCharges, ARInvoice.SalesTax1Amt, ARInvoice.SalesTax2Amt, ARInvoice.SalesTax3Amt, ARInvoice.OriginalAmount, ([ARInvoice].[OriginalAmount]-([ARInvoice].[FreightCharges]+[ARInvoice].[SalesTax1Amt]+[ARInvoice].[SalesTax2Amt]+[ARInvoice].[SalesTax3Amt])) AS True_Inv_total
FROM OESOQStatus INNER JOIN (ARSalesRep INNER JOIN (OESalesOrder INNER JOIN ((ARCustomer INNER JOIN ARInvoice ON ARCustomer.SKARCustomer = ARInvoice.FKARCustomer) INNER JOIN OEInvoice ON ARInvoice.SKARInvoice = OEInvoice.FKARInvoice) ON OESalesOrder.SKOESalesOrder = OEInvoice.FKOESalesOrder) ON ARSalesRep.SKARSalesRep = OESalesOrder.FKARSalesRep) ON OESOQStatus.StatusCode = OESalesOrder.Status
WHERE (((ARInvoice.InvoiceDate) Between #11/1/2009# And #12/31/2009#) AND ((ARInvoice.Status)=0 Or (ARInvoice.Status)=1) AND ((ARCustomer.Custom1)="yes"))
;
Looking for the end result totaling each customers group subtotal seperate and a grand total of the subtotals at the end example attached in excel. Want to see each invoices detail and a subtotal summary for each customer, then a grand total of all subtotal totals.

Answer : SQL subtotal, grand total by group

The way I used to do this is with multiple Selects into a temp table in SQL Server (or Union of selects in Access). The key is to add a Level column which would contain a number, from 1 to 5 for example, for each grouping level. Once the data is in Excel, you would then create the Subtotals and Groupings based on that column. Gives a really nice drill down capability to the report.

Leon
Random Solutions  
 
programming4us programming4us