SQL : in clause in stored procedure:how to pass values

前端 未结 8 1909
小蘑菇
小蘑菇 2020-11-27 18:12

I want to write a SQL Server 2005 stored procedure which will select and return the user records from the user table for some userids which are passed to the stored procedur

8条回答
  •  余生分开走
    2020-11-27 18:34

    you could use dynamic sql. Pass the in statement to a Sql SP via a variable and concatenate it into a query in the SQL and execute using sp_execute sql

    create procedure myproc(@clause varchar(100)) as 
    begin
      exec sp_executesql 'select * from users where userid in ( ' + @clause +' )'
    end
    

提交回复
热议问题