I have a query:
SELECT ID FROM requests WHERE date <operator> <expression>
I need to change <expression>
relying on my stored procedure's parameter.
If flag is set: WHERE date BETWEEN GETDATE() - 7 AND GETDATE()
If is not: WHERE date = date
I tried to use CASE-THEN but it forces using concrete operator but I have to have few:
SELECT ID FROM requests WHERE date = -- here it is
CASE
WHEN @flag = 1 THEN ..
ELSE date
END