Counting query yes/no and is not null

Pusher

BEOGRAD Put
Local time
Today, 12:55
Joined
May 25, 2011
Messages
230
Hi all,
I have a query that counts by month. It works fine when you count separately the yes/no field and is not null field but when I try to put them in the same query I get the same number in both counting fields.
Is there a way for this to work?
Thanks

Code:
SELECT Month([DATUM_IZVESTAJA]) AS MESEC, Count("ID_GRESKE") AS [BROJ ISPADA], Count("HAVARIJA") AS [BROJ HAVARIJA]
FROM IZVESTAJ
WHERE (((IZVESTAJ.HAVARIJA)=True)) OR (((IZVESTAJ.ID_GRESKE) Is Not Null))
GROUP BY Month([DATUM_IZVESTAJA]);
 
I don't know if I completely understand this, but I think you want to apply your WHERE criteria independently of each other. Try this:

Code:
SELECT Month([DATUM_IZVESTAJA]) AS MESEC, SUM(IIf(IsNull([ID_RESKE])=False, 1,0)) AS [BROJ ISPADA], SUM(IIf([HAVARIJA])=True, 1,0)) AS [BROJ HAVARIJA] 
FROM IZVESTAJ
GROUP BY Month([DATUM_IZVESTAJA]);

If not, post some sample input and output of the query.
 
That did it :) Only one thing - how can i make it read January, February an so on, and not 1 2 3 :)
 
Use the MonthName function:

Code:
SELECT MonthNane(Month([DATUM_IZVESTAJA])) AS MESEC, SUM(IIf(IsNull([ID_RESKE])=False, 1,0)) AS [BROJ ISPADA], SUM(IIf([HAVARIJA])=True, 1,0)) AS [BROJ HAVARIJA] 
FROM IZVESTAJ
GROUP BY Month([DATUM_IZVESTAJA]);
 

Users who are viewing this thread

Back
Top Bottom