I'm trying to retrieve the records from the joined tables based on 2 condition like below:
Where if(b.enddate is null)
a.starttime >= b.starttime
else
a.starttime >= b.starttime and a.endtime <= b.endtime
I have seen examples using case when but the result is not what I wanted. Please assist me to convert this condition into a proper sql format.
You don't need to use case
expression, this can be done using OR
in WHERE
clause
... Where
( b.enddate is null and a.starttime >= b.starttime)
or
( b.enddate is not null and a.starttime >= b.starttime and a.endtime <= b.endtime)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With