Hello, I'm trying to create a simply query that will count the number of StudentIDs for a given month, and return 0 if it gets a null response for any of the months. In SQL view it looks as follows:
SELECT Month([DateReceived]) AS Mnth, Count(tblStudent.StudID) AS CountOfStudID
FROM tblStudent INNER JOIN tblStudentLessons ON tblStudent.StudID = tblStudentLessons.StudID
WHERE (((tblStudentLessons.LessonID)=248) AND ((tblStudentLessons.DateReceived) Between #1/1/2009# And #12/31/2009#))
GROUP BY Month([DateReceived]);
This works fine except that if, for any of the months there are no StudentLessons received, the query skips that line, which causes problems in my report. I've tried using an IIf statement, as follows:
SELECT Month([DateReceived]) AS Mnth, Count(IIf([tblStudent.StudID] Is Null,0,([tblStudent.StudID]))) AS StudIDCount
FROM tblStudent INNER JOIN tblStudentLessons ON tblStudent.StudID = tblStudentLessons.StudID
WHERE (((tblStudentLessons.LessonID)=248) AND ((tblStudentLessons.DateReceived) Between #1/1/2009# And #12/31/2009#))
GROUP BY Month([DateReceived]);
but this doesn't work either (I get the same result set with skipped lines for null months).
Any suggestions on this would be much appreciated. Thanks!
SELECT Month([DateReceived]) AS Mnth, Count(tblStudent.StudID) AS CountOfStudID
FROM tblStudent INNER JOIN tblStudentLessons ON tblStudent.StudID = tblStudentLessons.StudID
WHERE (((tblStudentLessons.LessonID)=248) AND ((tblStudentLessons.DateReceived) Between #1/1/2009# And #12/31/2009#))
GROUP BY Month([DateReceived]);
This works fine except that if, for any of the months there are no StudentLessons received, the query skips that line, which causes problems in my report. I've tried using an IIf statement, as follows:
SELECT Month([DateReceived]) AS Mnth, Count(IIf([tblStudent.StudID] Is Null,0,([tblStudent.StudID]))) AS StudIDCount
FROM tblStudent INNER JOIN tblStudentLessons ON tblStudent.StudID = tblStudentLessons.StudID
WHERE (((tblStudentLessons.LessonID)=248) AND ((tblStudentLessons.DateReceived) Between #1/1/2009# And #12/31/2009#))
GROUP BY Month([DateReceived]);
but this doesn't work either (I get the same result set with skipped lines for null months).
Any suggestions on this would be much appreciated. Thanks!