Let's say I have a simple sales order table like ...
SaleID Agent SaleDate
1 A1 7/6/07
2 B2 7/25/07
3 A1 8/12/07
4 C3 8/14/07
5 C3 9/6/07
6 A1 9/10/07
And I want to count each agent's sales within the quarter by month. This is easy with a simple grouping query like ...
SELECT Agent, Format([SaleDate],"mmm yy") AS SaleMo, Count(SaleID) AS Sales
FROM [zz test]
GROUP BY Agent, Format([SaleDate],"mmm yy"), Month([SaleDate])
ORDER BY Agent, Month([SaleDate]);
and I get these results ...
Agent SaleMo Sales
A1 Jul 07 1
A1 Aug 07 1
A1 Sep 07 1
B2 Jul 07 1
C3 Aug 07 1
C3 Sep 07 1
So far, so good. But what I really want is the result set to include one row per agent for each month of the quarter whether they had any sales or not, so that my query result would be ...
Agent SaleMo Sales
A1 Jul 07 1
A1 Aug 07 1
A1 Sep 07 1
B2 Jul 07 1
B2 Aug 07 0
B2 Sep 07 0
C3 Jul 07 0
C3 Aug 07 1
C3 Sep 07 1
It seems like this should be simple, but I can't figure out how to "force" a zero row for EACH agent for EACH month in which each agent has no sales.
Does anyone know how to make this happen?
Thanks a million if you do!
Joe
SaleID Agent SaleDate
1 A1 7/6/07
2 B2 7/25/07
3 A1 8/12/07
4 C3 8/14/07
5 C3 9/6/07
6 A1 9/10/07
And I want to count each agent's sales within the quarter by month. This is easy with a simple grouping query like ...
SELECT Agent, Format([SaleDate],"mmm yy") AS SaleMo, Count(SaleID) AS Sales
FROM [zz test]
GROUP BY Agent, Format([SaleDate],"mmm yy"), Month([SaleDate])
ORDER BY Agent, Month([SaleDate]);
and I get these results ...
Agent SaleMo Sales
A1 Jul 07 1
A1 Aug 07 1
A1 Sep 07 1
B2 Jul 07 1
C3 Aug 07 1
C3 Sep 07 1
So far, so good. But what I really want is the result set to include one row per agent for each month of the quarter whether they had any sales or not, so that my query result would be ...
Agent SaleMo Sales
A1 Jul 07 1
A1 Aug 07 1
A1 Sep 07 1
B2 Jul 07 1
B2 Aug 07 0
B2 Sep 07 0
C3 Jul 07 0
C3 Aug 07 1
C3 Sep 07 1
It seems like this should be simple, but I can't figure out how to "force" a zero row for EACH agent for EACH month in which each agent has no sales.
Does anyone know how to make this happen?
Thanks a million if you do!
Joe