I have 2 tables. One simply lists every day of the year. The other, lists various data, including a date field. I need to create a query that will tell me how many records exist for each day of the year. Not all days of the year exist in the table, but I need to display every date of the year and if there are no records for that date, display 0. I have tried several variations, but cannot get what I need. For example, this:
SELECT Calendar.[Date], COUNT(Calendar.[Date]) AS myCount FROM
(SELECT [Date] FROM Daily WHERE Job = 'Preventive') AS Daily
RIGHT JOIN Calendar ON Daily.Date = Calendar.Date
GROUP BY Calendar.[Date]
HAVING Calendar.[Date] BETWEEN #1/1/2005# AND #1/31/2005#
The above gives me a count of 1 for all dates that do not exist in the table named Daily, instead of a 0.
SELECT Calendar.[Date], COUNT(Calendar.[Date]) AS myCount FROM
(SELECT [Date] FROM Daily WHERE Job = 'Preventive') AS Daily
RIGHT JOIN Calendar ON Daily.Date = Calendar.Date
GROUP BY Calendar.[Date]
HAVING Calendar.[Date] BETWEEN #1/1/2005# AND #1/31/2005#
The above gives me a count of 1 for all dates that do not exist in the table named Daily, instead of a 0.