使用"IN"中的值将逗号分隔的值从.NET传递到存储过程.SQL函数 [英] Passing comma-separated value from .NET to stored procedure using the value in "IN" SQL function

查看:84
本文介绍了使用"IN"中的值将逗号分隔的值从.NET传递到存储过程.SQL函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似于以下内容的SQL查询:

I have an SQL query similar to the following:

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

现在,我需要通过.net应用程序传递 @ param1 的值,以使上述查询有效.

Now I need to pass the value of @param1 from my .net application in such a way that the above query works.

有人可以建议我如何从我的VB.NET代码中传递一个类似于下面的值:

Can some one please advise me on how to pass from my VB.NET code a value which is similiar to below:

'1','2','3'

我的主要问题是如何从.NET应用程序中构造上述示例的参数值?

My main question is how do I structure value of parameter like above example from my .NET application?

推荐答案

像这样,我会创建一个表值函数会对其进行解析,以便您可以进行

quickly like that, I would create a table valued function that would parse it so you can do

   select * 
   from table 
   where field in (select field from dbo.myfunction(@param1))

这篇关于使用"IN"中的值将逗号分隔的值从.NET传递到存储过程.SQL函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆