I have a query that I need to be able to run for an entire year (once a month) and for each of my business areas (18 of them). So I'm looking for a way to generate results like the attached file (our regions are on the left - there are 18 of them) and each month of the year appears to the top of the page beginning from July (or Financial Year start) and ending in June.
Preferrably I'd like to be able to pass a parameter of the year to the query so this basically built the stats for the requested year (from July to June obviously).
I've attached the code I'm currently using to manually check each month of the year so far so this gives you an idea of what I'm looking to do. However, one of the stumbling blocks I see is that the query will return only the regions that have data. I need to be able to show if a region had 0 entries for that month (the data doesn't contain this obviously). So I'm wondering if every field needs to be 0 unless overwritten by a value from the query but as I say I'm not sure about this part.
Any advice/assistance that you can offer is appreciated.
SELECT COUNT(FilteredAccount.new_region) AS Awards
FROM FilteredAccount INNER JOIN
FilteredOpportunity ON FilteredAccount.accountid = FilteredOpportunity.accountid
WHERE ((FilteredOpportunity.new_fundsreleaseddate >= '01/01/2009') AND (FilteredOpportunity.new_fundsreleaseddate <= '01/31/2009')) AND ((FilteredOpportunity.new_producttype <> 6) OR ((FilteredOpportunity.new_startupflag = 1) AND ((FilteredOpportunity.new_startupdate >= '01/01/2009') AND (FilteredOpportunity.new_startupdate <='01/31/2009'))) )
GROUP BY FilteredAccount.new_region
ORDER BY FilteredAccount.new_region