游标定义查询语句传参数遇到问题
create procedure p_test
declare @idx_logistics nvarchar(500)
as
begin
declare a_test cursor scroll
for select * from wx_name where idx_logistics in (@idx_logistics)
。。。。。。
具体是这样的,idx_logistics列是整型的,@idx_log传过来的值是字符串,传进来的值是这样的,
例如:'1','2','3','4','5',查询多条。
上面的查询语句那样写有问题,报错:不能将nvarchar类型转化为int,请教各位怎么样写才对???
end;
[解决办法]
肯定不行了,你的把传来的参数截成一个一个的数字字符,再转换成int型用charindex()实现截成一个一个的字符
[解决办法]
create table testtb(col int)insert into testtbselect 1 union all select 2 union all select 3 union allselect 4 union all select 7 union all select 8 declare @p varchar(20) set @p='3,4,7'--这样是不行的--select * from @t where col in (@p)--这样是可以的select * from testtb where charindex(','+ltrim(col)+',',','+@p+',')>0/*col-----------347*/--或者exec('select * from testtb where col in ('+@p+')')/*col-----------347*/