Passing comma-separated value from .NET to stored procedure using the value in “IN” SQL function

前端 未结 3 1898
粉色の甜心
粉色の甜心 2021-01-13 04:12

I have an SQL query similar to the following:

create procedure test
(
   @param1 nvarchar(max)
)
as
begin
    select * from table where column1 in (@param1)
         


        
3条回答
  •  醉梦人生
    2021-01-13 04:35

    I don't think the problem is in the values you are passing. @param1 is just a string.

    You need to address this in your procedure. Your select statement will not be able to recognize the values in you IN clause. One solution is to take the comma-separated string and insert each record into a table variable Explained Here

    If your table variable is table @param_list, you procedure test looks like:

    create procedure test ( @param1 nvarchar(max) ) 
    as begin 
    select * from table where column1 in (Select thefield from @param_list); 
    end
    

提交回复
热议问题