I have \'param1, param2, parma3\'
coming from SSRS to a stored procedure as a varchar
parameter: I need to use it in a query\'s IN
cla
"Best way" is arguable, but one classic approach that remains without "creating functions and table parameters" is to simply employ dynamic SQL in the stored procedure:
-- FORNOW: local to act as the SP param and arg
declare @values varchar(100) = 'param1, param2, param3'
-- Add opening and closing single quotes, then quotes around each
-- comma-separated list item.
select @values = '''' + REPLACE(@values, ', ', ''', ''') + ''''
-- FORNOW: for clarity/debugging
print @values
--'param1', 'param2', 'param3'
-- Run the desired query as dynamic SQL.
DECLARE @sql as nvarchar(250);
SET @sql = 'select * from table1 where col1 in (' + @values + ')';
EXEC sp_executesql @sql;
This assumes a couple things, though: