My goal is to only select rows of a certain type that is dependent on the @Daily parameter, I am wondering whether its possible to use an IN statement within a case statement.. Below is how I've currently got this working in two separate statements, but as you can see most of the code is redundant other than the where clause of each statement.
IF @Daily = 1
SELECT DISTINCT Column001, Column002, Column003, Column004
FROM table1
INNER JOIN table2 ON table2.Ref = table1.Ref
INNER JOIN table3 ON table3.Ref= table2.Ref
WHERE table3.Type IN (1, 2, 3, 4)
IF @Daily = 0
SELECT DISTINCT Column001, Column002, Column003, Column004
FROM table1
INNER JOIN table2 ON table2.Ref = table1.Ref
INNER JOIN table3 ON table3.Ref= table2.Ref
WHERE table3.Type IN (5, 6, 7, 8)
This isn't valid syntax but I was wondering whether something like this was possible?
SELECT DISTINCT Column001, Column002, Column003, Column004
FROM table1
INNER JOIN table2 ON table2.Ref = table1.Ref
INNER JOIN table3 ON table3.Ref= table2.Ref
WHERE CASE WHEN @Daily = 1 THEN table3.Type IN (1, 2, 3, 4)
WHEN @Daily = 0 THEN table3.Type IN (5, 6, 7, 8)
END;
Is something like this possible? Unfortunately I can't add a daily flag onto the table itself for this task which would have bene nice to have.