日期:2014-05-17  浏览次数:20518 次

这个语句正确吗
insert into k07 (a0188,k0700,k0701) 
select * from (select a.a0188,convert(char(10),c.cardtime,23) k0700,convert(char(8),c.cardtime,24) k0701
from a01 a ,hwatt..kqz_employee b,hwatt..kqz_card c 
where a.a0190=b.employeecode and b.employeeid=c.employeeid) a
 where not exists (select*from k07)
------解决方案--------------------
INSERT  INTO k07
         ( a0188 ,
           k0700 ,
           k0701
         )
         SELECT  *
         FROM    ( SELECT    a.a0188 ,
                             CONVERT(CHAR(10), c.cardtime, 23) k0700 ,
                             CONVERT(CHAR(8), c.cardtime, 24) k0701
                   FROM      a01 a ,
                             hwatt..kqz_employee b ,
                             hwatt..kqz_card c
                   WHERE     a.a0190 = b.employeecode
                             AND b.employeeid = c.employeeid
                 ) a
         WHERE   NOT EXISTS ( SELECT 1
                              FROM   k07
                              WHERE  a.主键 = k07.主键 )

------解决方案--------------------
insert into k07 (a0188,k0700,k0701) 
 select 

 from 
 (select 
a.a0188,convert(char(10),c.cardtime,23) k0700,convert(char(8),c.cardtime,24) k0701
 from a01 a ,hwatt..kqz_employee b,hwatt..kqz_card c 
 where a.a0190=b.employeecode and b.employeeid=c.employeeid) a
 where 
not exists (select*from k07 where a0188=a.a0188 and k0700=a.k0700 and k0701=a.k0701)