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

前端 未结 8 1908
小蘑菇
小蘑菇 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:40

    try this this works for me

    DECLARE @InClause NVARCHAR(100)
    SET @InClause = 'tom,dick,harry'
    DECLARE @SafeInClause NVARCHAR(100)
    SET @SafeInClause = ',' + @InClause + ',' 
    SELECT * FROM myTable WHERE PATINDEX(',' + myColumn + ',', @SafeInClause) > 0
    

提交回复
热议问题