I need to add a case
statement in a where
clause. I want it to run either statement below depending on the value of TermDate.
Select *
from myTable
where id = 12345
AND TermDate CASE
WHEN NULL THEN
AND getdate() BETWEEN StartDate AND DATEADD(dd, 30, StartDate)
ELSE
AND GETDATE < TermDate
END
Since we all posted three exact answers, obviously too much, here a version that uses your
case when
construction.use this:
Why not just use an
OR
condition?You can accomplish this using
ANDs
andORs
. Try the following query.