MYSQL Case in select statement for checking null
mysql, sql
Solution
try using `IF`
SELECT guides.Gud_Id
, guides.Gud_Image
, guides.Gud_SubEditor
, guides.Gud_Reprint_Status
, guides.Gud_Publish_Date
, guides.Gud_Img_Chk
, guides.Gud_Published
, guides.Gud_View
, IF(guides.Gud_Publish_Date IS NULL,'Unscheduled','Forth Coming Titles')
AS Schedules
FROM guides
or if you really want `CASE`
SELECT guides.Gud_Id
, guides.Gud_Image
, guides.Gud_SubEditor
, guides.Gud_Reprint_Status
, guides.Gud_Publish_Date
, guides.Gud_Img_Chk
, guides.Gud_Published
, guides.Gud_View
, (
CASE
WHEN guides.Gud_Publish_Date IS NULL
THEN 'Unscheduled'
ELSE 'Forth Coming Titles'
END
) AS Schedules
FROM guides
Problem
in MySQL query if I pass: ``` case guides.Gud_Publish_Date when null then "Unscheduled" else "Forth Coming Titles" end ``` then it is considering all is null even the Gud_Publish_Date has value also. the full SQL statement is ``` SELECT guides.Gud_Id , guides.Gud_Image , guides.Gud_SubEditor , guides.Gud_Reprint_Status , guides.Gud_Publish_Date , guides.Gud_Img_Chk , guides.Gud_Published , guides.Gud_View , ( CASE guides.Gud_Publish_Date WHEN NULL THEN "Unscheduled" ELSE "Forth Coming Titles" END ) AS Schedules FROM guides ```