How to write a case in mysql query which checks for null or 0 for a particular column
CREATE TABLE tblConfirmationStatus (Confirm_Status TINY INT)
INSERT INTO tblConfirmationStatus
Confirm_Status
VALUES
(1),
(0),
(1),
({null}),
(0),
(1),
({null})
Required Output
ConfirmStatus
Confirmed Not Confirmed Confirmed Not Confirmed Not Confirmed Confirmed Not Confirmed
0 or Null – Not Confirmed, 1-Confirmed
SELECT CASE Confirm_Status
WHEN NULL OR 0 THEN 'Not Confirmed'
ELSE 'Confirmed' END AS ConfirmStatus
FROM tblConfirmationStatus;
There’s two options for CASE statements – the one you posted, or:
But you could probably use:
NULLis the absence of a value, so checking for values above zero should fall into the same category as zero.