比如数据集是:
1、3、500、38、只能写成 select .. where id=1 or id=3 or..如果数据集上百个,不知道对效率影响多少还有其他办法吗,谢谢 

解决方案 »

  1.   


    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)
      

  2.   


    用or和in效果差不多的。
    可以考虑把1、3、500、38这些数据插入到临时表中,然后
    select a.* from 表名 a,临时表 b where a.id=b.id
      

  3.   

    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写成存储过程方便些