在存储过程中查询某多个ID值时遇到的问题:declare @ids nvarchar(1000)
set @ids='1,2,3'
select * from table where id in '+@ids+' //这样执行会遇到转换错误,但如果该条语句赋给一个变量在执行就没问题,我希望能在不将这条语句赋值的前提下执行
set @ids='1,2,3'
select * from table where id in '+@ids+' //这样执行会遇到转换错误,但如果该条语句赋给一个变量在执行就没问题,我希望能在不将这条语句赋值的前提下执行
declare @ids nvarchar(1000)
set @ids='1,2,3'
select * from table where charindex(','+id+',',','+@ids+',')>0
declare @s varchar(5000)
set @ids='1,2,3'
set @s='select * from test where id in ('+@ids+')'
print @s
exec(@s)
http://topic.csdn.net/u/20080726/23/45568f53-069f-472e-80b0-1361a72109de.html
declare @ids nvarchar(1000)
set @ids='1,2,3'
select * from table where charindex(','+rtrim(id)+',',','+@ids+',')>0