I have two related tables, tmain and a look up table for AccidentCauses. I can show all records for all accident causes (including those with no accidents) with the following SQL:-
SELECT tAccidentCauses.AccidentCause, Count(tMain.IncidentID) AS CountOfIncidentID
FROM tAccidentCauses LEFT JOIN tMain ON tAccidentCauses.AccidentCauseID = tMain.AccidentCause
GROUP BY tAccidentCauses.AccidentCause
ORDER BY Count(tMain.IncidentID) DESC;
However, I'd like to make it a parameter query so people can see accidents by year. When I use the SQL below, though I can only seem to show accident causes that have associated records. Anyone have an idea on what I need to do? Thanks in advance.
SELECT tAccidentCauses.AccidentCause, Count(tMain.IncidentID) AS CountOfIncidentID
FROM tAccidentCauses LEFT JOIN tMain ON tAccidentCauses.AccidentCauseID = tMain.AccidentCause
GROUP BY tAccidentCauses.AccidentCause, Year([incdate])
HAVING (((Year([incdate]))=[Enter Year]))
ORDER BY Count(tMain.IncidentID) DESC;
SELECT tAccidentCauses.AccidentCause, Count(tMain.IncidentID) AS CountOfIncidentID
FROM tAccidentCauses LEFT JOIN tMain ON tAccidentCauses.AccidentCauseID = tMain.AccidentCause
GROUP BY tAccidentCauses.AccidentCause
ORDER BY Count(tMain.IncidentID) DESC;
However, I'd like to make it a parameter query so people can see accidents by year. When I use the SQL below, though I can only seem to show accident causes that have associated records. Anyone have an idea on what I need to do? Thanks in advance.
SELECT tAccidentCauses.AccidentCause, Count(tMain.IncidentID) AS CountOfIncidentID
FROM tAccidentCauses LEFT JOIN tMain ON tAccidentCauses.AccidentCauseID = tMain.AccidentCause
GROUP BY tAccidentCauses.AccidentCause, Year([incdate])
HAVING (((Year([incdate]))=[Enter Year]))
ORDER BY Count(tMain.IncidentID) DESC;