Can I assign a list of strings to a variable for use in an IN statement without using Dynamic SQL?
I am developing a report in SSRS which allows the user to select one of three possible values as a parameter which in turn will assign values associated with that choice to an IN statement. Some parameters have a single value associated and some have several.
Cases 1 and 2 run properly, but case 3 does not because it is passed as a scalar value instead of a list. I have tried various ways of escaping the quotes around each item, but it does not work.
declare @items as varchar(50)
set @items =
CASE @parameter
WHEN 1 then 'first'
WHEN 2 then 'second'
WHEN 3 then 'third, fourth'
END
select column1
from table1
where column1 IN (@items)