select * from b where serid in (select SerID from a where perid='aaa')
select * from b where serid not in (select SerID from a where perid='aaa')

解决方案 »

  1.   

    SerID在表B里面不存在的结果集:select * from  B  where 
     exists(select *  from A where charindex(b.serid,a.serid)=0 ) 
      

  2.   

    SerID在表B里面存在的结果集:
    select * from  B  where 
     exists(select *  from A where charindex(b.serid,a.serid)>0 )
      

  3.   

    select * from 表B where charindex (','+serid+',',(select ','+serid+',' from 表A where pid=aaa))>0    --在表B里面存在
    select * from 表B where charindex (','+serid+',',(select ','+serid+',' from 表A where pid=aaa))<0    --在表B里面不存在
      

  4.   

    select * from 表B where charindex (serid,(select ','+serid+',' from 表A where pid=aaa))>0    --在表B里面存在
    select * from 表B where charindex (serid,',(select ','+serid+',' from 表A where pid=aaa))<0    --在表B里面不存在
      

  5.   

    不存在:
    select b.* from 表A a,表B b where charindex(b.SerID,','+a.SerID+',')=0 and a.PID='aaa'存在:
    select b.* from 表A a,表B b where charindex(b.SerID,','+a.SerID+',')>0 and a.PID='aaa'
      

  6.   

    不存在:
    select b.* from 表A a,表B b where charindex(','+b.SerID+',',','+a.SerID+',')=0 and a.PID='aaa'存在:
    select b.* from 表A a,表B b where charindex(','+b.SerID+',',','+a.SerID+',')>0 and a.PID='aaa'