As a background, I’m creating a database of audits. These are supposed to be carried out by various departments every month, though the exact date within the month doesn’t matter.
One report I need to generate is a grid showing whether or not an audit has been carried out, for every department and month (over a variable date range). I have tried to create a crosstab query to do this, but with limited success. The SQL for my first attempt was as follows:
TRANSFORM Count(qryReportAudits.AuditID) AS [The Value] SELECT qryReportAudits.Name, qryReportAudits.Description FROM qryReportAudits GROUP BY qryReportAudits.Name, qryReportAudits.Description PIVOT Format([Date],"mmm") In ("Jan","Feb","Mar","Apr","May", "Jun","Jul","Aug","Sep","Oct","Nov","Dec");
This lumps all audits into each month, regardless of what year they belong to. The SQL for my second attempt was as follows:
TRANSFORM Count(qryReportAudits.AuditID) AS [The Value] SELECT qryReportAudits.Name, qryReportAudits.Description FROM qryReportAudits GROUP BY qryReportAudits.Name, qryReportAudits.Description PIVOT Format([Date],"yyyy mm");
This correctly separates audits by both year and month, but misses out months in which no audit took place.
Can anyone think of a way I can show all years and months for the required range, without missing out any? (Hope all that makes sense!)