SQL use comma-separated values with IN clause

前端 未结 9 1770
终归单人心
终归单人心 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:04

    The way you are trying to do this is slightly wrong. You will need to use EXECUTE in order to achieve this.

    CREATE PROCEDURE [dbo].[sp_getUserRoles](@pGroupIDs nvarchar(50))
    As
    BEGIN         
        EXECUTE (N'SELECT * FROM CheckList_Groups Where id in (' + @pGroupIDs + ')';
    END 
    

提交回复
热议问题