当前位置: 代码迷 >> Sql Server >> 存储过程中是数组型的参数,该怎么处理
  详细解决方案

存储过程中是数组型的参数,该怎么处理

热度:12   发布时间:2016-04-27 14:52:57.0
存储过程中是数组型的参数
参数类型是这样的:001,002,003

请问 在存储过程中 如何使用这样参数


如传入

exec pro_test "001,002,003"

执行为select* from test where id=001 or id=002 or id=003

------解决方案--------------------
SQL code
exec pro_test 001,002,003
------解决方案--------------------
exec pro_test "'001','002','003'"


存储过程这样写
declare @sql nvarchar(500)
select @sql='select * from test where id in([email protected]+')'
exec(@sql)
------解决方案--------------------
改:exec pro_test '''001'',''002'',''003'''
------解决方案--------------------
SQL code
create proc pro_test(@id varchar(200))asbegin    declare @sql varchar(800)    set @sql='select * from test where id in([email protected]+')'    print @sqlendexec pro_test '001,002,003' --执行结果select * from test where id in(001,002,003)或者exec pro_test '''001'',''002'',''003''' --执行结果select * from test where id in('001','002','003')
  相关解决方案