各位大师好:
我想请问一个问题:
字段A 
    11
    22
    33怎么能得到这样的结果:
select * from 表 where a in (11,22,33,44,55)  结果为空,就是没有数据。
意思是当IN 的里面包含了字段A数值以外的数值 就判断 得到空结果,谢谢指导。 

解决方案 »

  1.   

    select * from 表 where a not in (11,22,33,44,55)
      

  2.   

    不能用IN,或许该用not exists()
      

  3.   

    怎么能得到这样的结果: 
    select * from 表 where a in (11,22,33,44,55)  结果为空,就是没有数据。 
    意思是当IN 的里面包含了字段A数值以外的数值 就判断 得到空结果,谢谢指导。 IN的里面的东西不在表字段里面?什么逻辑?
      

  4.   


    select * from 表 where 
     exists(select * from 表 where a not in (11,22,33,44,55) )
      

  5.   

    对不起 我没鞋清楚 我的 意思就是说 如果 in 的里面 包括了 字段A没有的数据 结果就返回为空,嘿嘿 
      

  6.   

    6楼的老师 如果 
    select * from ff where 
     exists(select * from ff where a not in (11,22,33))
    这样还是返回为空啊 
      

  7.   

    变通一下:
    declare @t table(ColA int)
    insert into @t select 11 
    insert into @t select 22 
    insert into @t select 33 select
        t.*
    from
        @t t
    where
        t.ColA in(11,33)
        and  
        exists(select * from @t where ColA in(11,33) having count(distinct ColA)=(len('11,33')-len(replace('11,33',',',''))+1))
    /*
    ColA        
    ----------- 
    11
    33
    */select
        t.*
    from
        @t t
    where
        t.ColA in(11,22,33)
        and  
        exists(select * from @t where ColA in(11,22,33) having count(distinct ColA)=(len('11,22,33')-len(replace('11,22,33',',',''))+1))
    /*
    ColA        
    ----------- 
    11
    22
    33
    */select
        t.*
    from
        @t t
    where
        t.ColA in(11,22,33,44)
        and  
        exists(select * from @t where ColA in(11,22,33,44) having count(distinct ColA)=(len('11,22,33,44')-len(replace('11,22,33,44',',',''))+1))
    /*
    ColA        
    ----------- 
    */
      

  8.   


    select *
    from ta
    where charindex(','+ltrim(cola)+',',',11,22,33,44,55,') =0
      

  9.   


    来个简单的select * from 表 where  charindex(','+a+',',','+'11,22,33,44,55'+',')> 0 
      

  10.   


    declare @t table(ColA int)
    insert into @t select 11 
    insert into @t select 22 
    insert into @t select 33
    insert into @t select 88 
    select * from @t where  charindex(','+cast(ColA as nvarchar(10))+',',','+'11,22,33,44,55'+',')> 0 ColA
    -----------
    11
    22
    33(3 row(s) affected)