Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Total of Subtotal

Author  Topic 

Trini
Starting Member

9 Posts

Posted - 2006-06-09 : 12:34:58
I need to total filtered values each time the filter criteria changes.
So lets say I change the month to JAN then in addition to the subtotals for each category I need to get a Grand Total.
Thanks much.

SELECT Location, SUM(month_est) AS SubTot_Month_Est, SUM(actual) AS SubTot_Actual, mnth, yr
FROM dbo.meetings
GROUP BY Location, mnth, yr

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-06-09 : 14:28:27
You didn't really explain what you wanted, but maybe this might be close to what you want.

If it isn't, post your table structure, some smaple data, and what you want your output to look like.


SELECT
Location,
yr,
mnth,
SUM(month_est) AS SubTot_Month_Est,
SUM(actual) AS SubTot_Actual
FROM
dbo.meetings
GROUP BY
Location,
yr,
mnth
with rollup
order by
Location,
yr,
mnth




CODO ERGO SUM
Go to Top of Page

Trini
Starting Member

9 Posts

Posted - 2006-06-09 : 14:41:46
This works fine.
Thanks.


quote:
Originally posted by Michael Valentine Jones

You didn't really explain what you wanted, but maybe this might be close to what you want.

If it isn't, post your table structure, some smaple data, and what you want your output to look like.


SELECT
Location,
yr,
mnth,
SUM(month_est) AS SubTot_Month_Est,
SUM(actual) AS SubTot_Actual
FROM
dbo.meetings
GROUP BY
Location,
yr,
mnth
with rollup
order by
Location,
yr,
mnth




CODO ERGO SUM

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-06-10 : 03:23:38
If you use Reports, then make use of its aggregate function

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -