I have a parameter in a SQL Server Reporting Services report, @Status, that can have one or more values:
SSRS then of course passes it into my embedded query as ('Open'), or ('Open', 'Neutral'), etc, and I can filter on it in the WHERE clause:
However, now I need to also filter based on a date field if "Open" is the *only* status chosen. Stated differently, if the user is only viewing the Open records, they only want records after a certain date. Loosely, the logic goes like this:
I hope that makes sense.
Anyone know how to test for a multi-value parameter in that manner? I've come up with solutions that work as long as only a single value is chosen for @Status (I'll post them in a minute), but they fail when @Status comes in with two or more values chosen.
Thanks in advance.
Code:
@Status = Open
@Status = Closed
@Status = Neutral
SSRS then of course passes it into my embedded query as ('Open'), or ('Open', 'Neutral'), etc, and I can filter on it in the WHERE clause:
Code:
SELECT *
FROM table1
WHERE fieldStatus IN (@Status)
However, now I need to also filter based on a date field if "Open" is the *only* status chosen. Stated differently, if the user is only viewing the Open records, they only want records after a certain date. Loosely, the logic goes like this:
Code:
SELECT *
FROM table1
WHERE fieldStatus IN (@Status)
AND
(CASE WHEN @Status = 'Open' AND COUNT(@Status) = 1 THEN fieldDate >= GETDATE() END)
I hope that makes sense.
Anyone know how to test for a multi-value parameter in that manner? I've come up with solutions that work as long as only a single value is chosen for @Status (I'll post them in a minute), but they fail when @Status comes in with two or more values chosen.
Thanks in advance.