SQL use comma-separated values with IN clause

前端 未结 9 1768
终归单人心
终归单人心 2020-12-19 08:49

I am developing an ASP.NET application and passing a string value like \"1,2,3,4\" into a procedure to select those values which are IN (1,2,3,4) but its saying \"Conversion

9条回答
  •  天涯浪人
    2020-12-19 09:15

    You need to use SP_executesql to achieve this functionllity

    CREATE Procedure [dbo].[sp_getUserRoles](
       @pGroupIDs varchar(50)
        )
         As
        BEGIN
    
    EXECUTE sp_executesql 
              N'SELECT * FROM CheckList_Groups Where id in (@pGroupIDs)',
              N'@level varchar(50)',
              @level = @pGroupIDs;
    
     End
    

提交回复
热议问题