I couldn't find an answer from searching - its hard to craft a search with these items (SQL, count, where, zero) and not get a billion hits.
If I use the following query, I get a count by room (from qryPriRoomCode) of the total number of messages associated with that room even if the number is zero.
SELECT DISTINCT qryPriRoomCode.PriRoomCode, Count(qrySyslogRoomMatch.MsgUnique) AS CountOfMsgUnique
FROM qryPriRoomCode LEFT JOIN qrySyslogRoomMatch ON qryPriRoomCode.PriRoomCode = qrySyslogRoomMatch.RoomCode
GROUP BY qryPriRoomCode.PriRoomCode;
But, if I add a where clause to limit to a certain date and time range, I no longer get a 'LEFT JOIN' result. In other words, the messages are limited to the right date/time, but in the process, all zero results are thrown out:
SELECT DISTINCT qryPriRoomCode.PriRoomCode, Count(qrySyslogRoomMatch.MsgUnique) AS CountOfMsgUnique
FROM qryPriRoomCode LEFT JOIN qrySyslogRoomMatch ON qryPriRoomCode.PriRoomCode=qrySyslogRoomMatch.RoomCode
WHERE (((qrySyslogRoomMatch.MsgDate)=Date()) AND ((qrySyslogRoomMatch.MsgTime)>DateAdd("h",-1,Time())))
GROUP BY qryPriRoomCode.PriRoomCode;
I think I know why this is happening - I just don't know what a good solution would be. I want the results to show the number of messages per room received in the last hour even if that number is zero.
Any help is appreciated,
t
If I use the following query, I get a count by room (from qryPriRoomCode) of the total number of messages associated with that room even if the number is zero.
SELECT DISTINCT qryPriRoomCode.PriRoomCode, Count(qrySyslogRoomMatch.MsgUnique) AS CountOfMsgUnique
FROM qryPriRoomCode LEFT JOIN qrySyslogRoomMatch ON qryPriRoomCode.PriRoomCode = qrySyslogRoomMatch.RoomCode
GROUP BY qryPriRoomCode.PriRoomCode;
But, if I add a where clause to limit to a certain date and time range, I no longer get a 'LEFT JOIN' result. In other words, the messages are limited to the right date/time, but in the process, all zero results are thrown out:
SELECT DISTINCT qryPriRoomCode.PriRoomCode, Count(qrySyslogRoomMatch.MsgUnique) AS CountOfMsgUnique
FROM qryPriRoomCode LEFT JOIN qrySyslogRoomMatch ON qryPriRoomCode.PriRoomCode=qrySyslogRoomMatch.RoomCode
WHERE (((qrySyslogRoomMatch.MsgDate)=Date()) AND ((qrySyslogRoomMatch.MsgTime)>DateAdd("h",-1,Time())))
GROUP BY qryPriRoomCode.PriRoomCode;
I think I know why this is happening - I just don't know what a good solution would be. I want the results to show the number of messages per room received in the last hour even if that number is zero.
Any help is appreciated,
t