declare @s varchar(4000) set @s='1,3,500,38' ---加exec('select* from tb where id in ('+@s+')'----------------------------------------------select * from tb where id=1 union all select * from tb where id=500 ..... -----------------------------------------------把那个放到表里select * from tb where id in (select id from #t)
用or和in效果差不多的。 可以考虑把1、3、500、38这些数据插入到临时表中,然后 select a.* from 表名 a,临时表 b where a.id=b.id
create proc kkk @s varchar(4000)=null as begin set @s=isnull(@s,'1,3,500,38' ) exec('select* from tb where id in ('+@s+')' end写成存储过程方便些
declare @s varchar(4000)
set @s='1,3,500,38' ---加exec('select* from tb where id in ('+@s+')'----------------------------------------------select * from tb where id=1
union all
select * from tb where id=500
.....
-----------------------------------------------把那个放到表里select * from tb where id in (select id from #t)
用or和in效果差不多的。
可以考虑把1、3、500、38这些数据插入到临时表中,然后
select a.* from 表名 a,临时表 b where a.id=b.id
@s varchar(4000)=null
as
begin
set @s=isnull(@s,'1,3,500,38' )
exec('select* from tb where id in ('+@s+')'
end写成存储过程方便些