Can I use different selection comparisons based on a passed value in SQL?
I wasn't really sure of the best wording for the question but here is my dilemma:
I am passing a value to a sql query as @district. This value may be the exact district but it also has the possibility of being a value that should create a set of multiple districts. So if I pass '002' I want the where clause to say I.Offense_Tract = @district. If I pass 'Other' I want the where clause to say I.Offense_Tract in (). What I am trying to do is something like:
AND
CASE
WHEN @district = "Other" THEN I.Offense_Tract in ('BAR','COL','GER','MEM','MIL','JAIL','JAILEAST','SCCC','1USD','2USD')
ELSE I.Offense_Tract = @district
END
But this doesn't work. The problem, restated, is if the value passed is anything other than 'Other', I just want it to be =. If 'Other' is passed, I want it to be IN.
from Recent Questions - Stack Overflow https://ift.tt/3C1CYjk
https://ift.tt/eA8V8J
Comments
Post a Comment