Using a comma-separated parameter in an IN clause

后端 未结 5 1963
余生分开走
余生分开走 2021-01-05 11:34

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

5条回答
  •  隐瞒了意图╮
    2021-01-05 12:17

    Load the Params into a string and execute as an sql :

    declare @param varchar(1000) = 'param1, param2, parma3'
    declare @sql varchar(4000)
    select @sql = 
    'select *
    from table1
    where col1 in(''' + replace(@param,',',''',''') + ''')'
    
    -- print @sql -- to see what you're going to execute
    exec sp_executesql @sql
    

提交回复
热议问题