if exists(select TB1.* from TB1,TB2 where TB1.A =TB2.A and TB2.DT=convert(varchar(10),getdate(),120))
 insert into TB2(A,C,E,DT) select A,C,E,convert(varchar(10),Getdate(),120) from TB1

解决方案 »

  1.   

    insert into TB2(A,C,E,DT) 
    select 
        t.A,t.C,t.E,getdate() 
    from 
        TB1 t
    where 
        not exists(select 1 from TB2 where A=t.A and datediff(dd,DT,t.DT)=0)
      

  2.   

    上面那句半角输入逗号有错!改一下:
    if exists(select TB1.* from TB1,TB2 where TB1.A =TB2.A and TB2.DT=convert(varchar(10),getdate(),120))
    insert  TB2(A,C,E,DT) select A,C,E,convert(varchar(10),Getdate(),120) from TB1 A
      

  3.   

    insert into TB2(A,C,E,DT) 
    select 
        t.A,t.C,t.E,getdate() 
    from 
        TB1 t
    where 
        a not in(select id from TB2 where A=t.A and datediff(dd,DT,t.DT)=0)