select id,title from table where id in()?
其中括号里为用逗号隔开的多个数字的vachar类型,格式为12,23,25,34,54,请教怎么能得到这几个数值对应的结果?

解决方案 »

  1.   

    where charindex(',12,23,25,34,54,',','+ltrim(id)+',')>0
      

  2.   

    select id,title from table where id in ('12','23','25','34','54')
      

  3.   

    select id,title from table where id in ('12','23','25','34','54') order by id 
      

  4.   

    select id,title from table where charindex(',12,23,25,34,54,',','+ltrim(id)+',')>0
      

  5.   

    谢谢各位了,我还是用的in,开始测试的时候,有个地方没通过,还认为int的id不能用in呢。回来测试一下还是可以的。
      

  6.   

    int类型的也是可以的
    where id int(1,2,3,4,5,7,8)
      

  7.   

    where id in (1,2,3,4,5,7,8)  --应该是这样
      

  8.   


    --用charindex函数做where条件
    select id,title from table where charindex(','+id+',',',12,23,25,34,54,')>0