参数查询中的LIKE和IN表达式 [英] LIKE and IN expressions in parameter queries
问题描述
有谁知道怎么做?我想传递一个选择命令
参数,并将其用作与我的SQL数据进行LIKE / IN比较。
谢谢
Rob Oldfield写道:有没有人知道如何做到这一点?我想传递一个选择命令
参数,并将其用作LIKE / IN与我的SQL数据的比较。
谢谢
你以与任何其他INSERT或
UPDATE语句相同的方式传递它。
SELECT * FROM MYTABLE
WHERE ID IN(@ param1,@ param2)
" John Bailo" < JA ***** @ texeme.com>在消息中写道
news:Pr ****************************** @ speakeasy.ne t。 ..Rob Oldfield写道:有没有人知道如何做到这一点?我想传递一个select
命令参数,并将其用作与我的SQL数据进行LIKE / IN比较。
谢谢
<你以与任何其他INSERT或
UPDATE语句相同的方式传递它。
SELECT * FROM MYTABLE
WHERE ID IN(@ param1,@ param2 )
嗯。是的,这适用于INs那种方法意味着我必须知道如何在列表中找到很多物品(虽然我想它有可能
在设置中使用'太多''并将任何多余的值设置为不可能的
值。我所寻找的更多是从select * from
mytable where id in(@listparams),这样我就可以将@listparams设置为
单变量'''',''b'',''c' '或者其他什么。我刚刚尝试过它而且
不起作用。
如果我输入一个标准LIKE%@ param1%(如果那个'b
变成超链接,请忽略它)在Visual Studio中然后SQL语句
出来像LIKE N'' %@ p1%(同上)我甚至不会被要求获得
参数值,因为它只是将其作为文本。
Rob Oldfield写道:
在LIKE上,如果我在Visual Studio中输入一个LIKE%@ param1%的标准(如果那个'
变成一个超链接,请忽略它),那么SQL
声明
出现像LIKE N''%@ p1%(同上),我甚至不会被要求获得
参数值,因为它只是将其作为文本。
你真正想要的是一个SQL语句构建器类:
(1)接受一个值数组和一个SQL参数集合对象。
(2)使用StringBuilder并附加相同数量的@param名称
(@ param1,@ param2,l ...)
(3)然后,对于每个字符串,它.Add()sa参数为参数
集合。
(4)传回参数集合。
-
http://blog.360.yahoo.com/manfrommars_43
http://texeme.com
Does anyone have any idea how to do this? I want to pass a select command a
parameter and just use that as a LIKE/IN comparison with my SQL data.
Thanks
Rob Oldfield wrote:Does anyone have any idea how to do this? I want to pass a select command a
parameter and just use that as a LIKE/IN comparison with my SQL data.
Thanks
You pass it in the same way that you would for any other INSERT or
UPDATE statement.
SELECT * FROM MYTABLE
WHERE ID IN ( @param1, @param2 )
"John Bailo" <ja*****@texeme.com> wrote in message
news:Pr******************************@speakeasy.ne t...Rob Oldfield wrote:Does anyone have any idea how to do this? I want to pass a select command a parameter and just use that as a LIKE/IN comparison with my SQL data.
Thanks
You pass it in the same way that you would for any other INSERT or
UPDATE statement.
SELECT * FROM MYTABLE
WHERE ID IN ( @param1, @param2 )
Hmm. Yes, that works but for INs that method means that I have to know how
many items I''m going to have in the list (though I guess it''d be possible to
use ''too many'' in the setup and just set any redundant ones to an impossible
value. What I was looking for was more along the lines of select * from
mytable where id in (@listparams) so that I can set @listparams to be the
single variable ''a'',''b'',''c'' or whatever. I''ve just tried that and it
doesn''t work.
And on the LIKEs, if I enter a criterion of LIKE %@param1% (if that''s turned
into a hyperlink, please ignore it) in Visual Studio then the SQL statement
comes out as LIKE N''%@p1% (ditto) and I don''t even get asked for a
parameter value as it''s just taking it as text.
Rob Oldfield wrote:
And on the LIKEs, if I enter a criterion of LIKE %@param1% (if that''s
turned into a hyperlink, please ignore it) in Visual Studio then the SQL
statement
comes out as LIKE N''%@p1% (ditto) and I don''t even get asked for a
parameter value as it''s just taking it as text.
What you really want is a SQL statement builder class that:
(1) Takes in an array of values and a SQL parameter collection object.
(2) Uses StringBuilder and appends an equivalent number of @param names
(@param1, @param2, l...)
(3) Then, for each string, it .Add() s a parameter to the parameter
collection.
(4) Passes back the parameter collection.
--
http://blog.360.yahoo.com/manfrommars_43
http://texeme.com
这篇关于参数查询中的LIKE和IN表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!