Log in

View Full Version : case count issue



burnside
11-09-2009, 02:37 PM
Hi,

Need help with the following query - if there is a count for USED then no NEW are counted for each day, can anyone tell me why?



SELECT
CASE eventstocklink.statusid WHEN 2 THEN count(CB.actionid) ELSE 0 END AS USED,
CASE eventstocklink.statusid WHEN 1 THEN count(CB.actionid) ELSE 0 END AS NEW
FROM action AS CB
LEFT JOIN event ON event.eventid = CB.eventid
LEFT JOIN eventstocklink ON eventstocklink.eventstocklinkid = CB.eventstocklinkid
WHERE date(CB.actiondate)
BETWEEN '20091102' AND '20091108'
GROUP BY eventstocklink.statusid, date(CB.actiondate)


thanks in advance

burnside
11-09-2009, 10:14 PM
this solved my issue



, COUNT(CASE WHEN eventstocklink.statusid = 2
THEN CB.actionid END) AS USED
, COUNT(CASE WHEN eventstocklink.statusid = 1
THEN CB.actionid END) AS NEW

FiveForMe
11-21-2009, 08:47 PM
Hi,

CASE FBD for PLC & NovaPro SCADA:

Oops wrote: