Naitik dave Naitik dave - 3 months ago 9
MySQL Question

If Else condition in mysql to check null

How should I make if condition in mysql

where time = null
then I want result in NO else YES?

SELECT
case when TIME_TO_SEC(TIMEDIFF(Event01.EndTime ,Event01.StartTime)) != NULL THEN
@Loss:='YES'
ELSE
@Loss:='NO'
END AS Loss
from Event01,(SELECT @Loss:= 0) AS Loss

Answer

Try this, You have to check NULL using is clause.

SELECT
case when TIME_TO_SEC(TIMEDIFF(Event01.EndTime ,Event01.StartTime)) is not NULL THEN
    'YES'
    ELSE
    'NO'
    END AS Loss
from Event01

Hope it will help.