Another method is to do three queries - with UNION ALL between them. You need some "hidden" columns to accomplish the ordering of the data so that detail rows are followed by the proper sub-total row and that the grand total appears last.
We use this method often for on-screen displays of financial data exactly as you have shown.
*** Read the sticky in the DB forum about how to get your question answered quickly!! ***
Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".
Select SLFund,Sum(CreditAmt) "Credit",Sum(DebitAmt) "Debit"
From Ledger_T
Where FiscalYr=2007
Group by SLFund
Union All
Select 'Total',Sum(CreditAmt),Sum(DebitAmt)
From Ledger_T
Where FiscalYr=2007
Order by 1
I am ordering by column 1 - but you could easily "build" a sort column that is smart enough to put your subtotals at the bottom of each group and your grand total at the bottom.
*** Read the sticky in the DB forum about how to get your question answered quickly!! ***
Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".
"WHERE (tblClient_Consume_Products.DateOut BETWEEN '" & Format(DTPStart.Value, "mm-dd-yyyy") & "' AND '" & Format(DTPEnd.Value, "mm-dd-yyyy") & "' ) " & _
"GROUP BY tblClient.ClientName, tblClient.ClientBudget"
oConn.Execute sSQL1
Result of the above query:
ClientName Budget Purchase Selling
SOCO-Apopong 960.00 55.50 63.82
SOCO-Calumpang 960.00 56.25 64.68
Doctor's Hospital 3000.00 72.75 83.66
SOCO-Main 5000.00 147.75 169.90
I used the records of temporary table in Crystal Report 9. I used grouped by clientname and here is the result:
ClientName Budget Purchase Selling
Doctor's Hospital 3000.00 72.75 83.66
SOCO-Apopong 960.00 55.50 63.82
SOCO-Calumpang 960.00 56.25 64.68
SOCO-Main 5000.00 147.75 169.90
Total 9920.00 332.25 382.06
i want it to be like this:
SOCO-Apopong 960.00 55.50 63.82
SOCO-Calumpang 960.00 56.25 64.68
SOCO-Main 5000.00 147.75 169.90
Sub-Total 6920.00 259.50 298.40
Doctor's Hospital 3000.00 72.75 83.66
Sub-Total 3000.00 72.75 83.66
Grand Total 9920.00 332.25 382.06
Please Help me.
Last edited by Simply Me; Nov 22nd, 2007 at 08:00 PM.
To give is always to be NOBLE...
To received is always to be BLESSED....
Each day strive to be NOBLE
Each day strive to be BLESSED
If this post has helped you. Please take time to rate it.
Usually with a UNION ALL you need to fake a column that you can then order by.
I don't know what makes a SOCO vs a "Doctor's Hospital" different in your data - but let's assume it's a field called SocoFlag with a Y or N
Select x,y,z,Case When SocoFlag='Y' Then 'A' Else 'B' End + tblClient.ClientName...
Union All
Select 'Sub-Total',sum(y),sum(z),Case When SocoFlag='Y' Then 'AZZ' Else 'BZZ' End
Union All
Select 'Total',sum(y),sum(z),'C'
Order by 4
The 'A', 'B' or 'C' as the first character of the 4th column helps to group the data rows with the "sub-total" rows. Then you simply ORDER BY that column and everything comes out as expected.
*** Read the sticky in the DB forum about how to get your question answered quickly!! ***
Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".
SOCO and Doctor's are all client. I just wanted to get the subtotal of all SOCO Client and subtotal of the rest of the client and then get the grandtotal as what is reflected in the attachment. Thanks zslamany...I'll try to do what you said.
To give is always to be NOBLE...
To received is always to be BLESSED....
Each day strive to be NOBLE
Each day strive to be BLESSED
If this post has helped you. Please take time to rate it.