在操作员中使用变量作为值 [英] In Operator using varibale for values
本文介绍了在操作员中使用变量作为值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我正在使用In运算符,并将其值通过变量传递,但它没有返回任何值.使用变量值作为单个字符串的In运算符.
例如:-
声明@empid varchar(100)=(''k'',''b'',''c'')
从(@empid)中id的表中选择*
我应该怎么做才能解决它.
感谢您的帮助
问候..
dEV kASHYAP
Hello everybody,
I am using In operator and passing it values through a variable, but it is not returning any value. The In operator using varible''s value as a single string.
for example:-
declare @empid varchar(100) =(''k'',''b'',''c'')
select * from table where id in (@empid)
what i should do to solve it.
Thanks for any help
Regards..
dEV kASHYAP
推荐答案
似乎您的意思是:
It seems that you meant :
declare @empid varchar(100) = 'k,b,c'
所以解决方案是这样的:
So the solution is this :
declare @empid varchar(100) = 'k,b,c'
declare @xml xml
set @xml = N'<root><r>' + replace(@empid, ',','</r><r>') + '</r></root>'
select * from table where id in
(
select r.value('.','varchar(max)') as item
from @xml.nodes('//root/r') as records(r)
)
希望对您有所帮助.
Hope it helps.
尝试select * from table where id in ('' + @empid + '')''
在存储过程中构建动态SQL [ ^ ]应该可以帮助您
Tryselect * from table where id in ('' + @empid + '')''
Building Dynamic SQL In a Stored Procedure[^] should help you out.
这篇关于在操作员中使用变量作为值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文