需要建立一存储过程并实现下面功能: 传入某一个或多个ID值,如:11,22,33,44....(传入该参数的个数不定)
这个参数传入存储过程需将传入ID值的参数进行分别查询,并且数据合并在一起,如:
select id from table where id=11
union
select id from table where id=22
union
select id from table where id=33
.... 因为其传入的id的个数不确定,而且需在存储过程中进行对ID参数进行分割和循环,具体如何实现,请各指点下.
这个参数传入存储过程需将传入ID值的参数进行分别查询,并且数据合并在一起,如:
select id from table where id=11
union
select id from table where id=22
union
select id from table where id=33
.... 因为其传入的id的个数不确定,而且需在存储过程中进行对ID参数进行分割和循环,具体如何实现,请各指点下.
直接传'11,22,33,44...'这个字符串进去好了呀。假定是@IDs参数
declare @sql nvarchar(4000)
set @sql=N'select id from table where id in ('+@IDs+')'
exec sp_executesql @sql
如果不赋值给@sql,直接执行会遇到转换问题,这句有没有在不赋值的情况下解决传入IDS转换问题