有两个表
M表
字段 Q
   12A54
     B89
   89C46
   .....
N表
字段 T
     A
     B
     C
     D
   .....
我想找出字段 T中记录没有在字段 Q中记录出现的记录.在线等.

解决方案 »

  1.   

    declare @m table(Q varchar(20))
    insert @m
    select  '12A54' union all
    select  'B89' union all
    select  '89C46'
    declare @n table(T varchar(10))
    insert @n
    select 'A' union all
    select 'B' union all
    select 'C' union all
    select 'D'select * from @n a 
    where not exists(select 1 from @m b where charindex(a.T,b.Q) > 0)/*结果
    D
    */
      

  2.   


    create table m(q varchar(20))
    insert into m(q)
    select '12A54'
    union all select 'B89'
    union all select '89C46'
    create table n(t varchar(20))
    insert into n(t)
    select 'A' 
    union all select 'B'
    union all select 'C'
    union all select 'D'declare @str varchar(8000)
    select @str = isnull(@str,'')+q from mselect * from n
    where charindex(n.t,@str)<=0drop table m
    drop table n