I need help with my query:
When I send to the query a parameter with the value -1, I would like to filter with ‘IN’ statement, otherwise filter according the value.
I was trying to do something like this:
WHERE (StatusId = CASE WHEN @StatusId = - 1
THEN
@StatusId IN (1, 2, 3)
ELSE
StatusId = @StatusId END)
Thanks.
I think you have a typo in your example, as the following:
… won’t do anything since if
@StatusId = -1, it won’t bein (1, 2, 3).Anywhos, you can just use
ORand nested parentheses: