Been digging around, but can't get this to work, and I'm not sure if it's possible this way. I'm trying to add a Case to the IN Clause. The problem is in this case it needs to be a list. I may be missing something obvious here, but there's the basic idea:
When using that approach I get a syntax error converting '1,2,3' to INT (the field is an INT). If I don't enclose the list in quotes the CASE generates a syntax error near ,.
The only other approach I can think of at the moment (and one I'd like to avoid due to complexity of other sections) is to build the IN statement as a variable, then build the entire statement into a variable to exec.
Code:
DECLARE @Var INT
SET @Var = 1
SELECT *
FROM [TABLE]
WHERE [FIELD] IN (CASE @Var
WHEN 1 THEN ('1,2,3')
WHEN 2 THEN ('4,5,6')
END)
When using that approach I get a syntax error converting '1,2,3' to INT (the field is an INT). If I don't enclose the list in quotes the CASE generates a syntax error near ,.
The only other approach I can think of at the moment (and one I'd like to avoid due to complexity of other sections) is to build the IN statement as a variable, then build the entire statement into a variable to exec.