db2 批量插入数据去重复
开发过程遇到 两张表字段相同,但是需要将旧表数据插入新表,如果新表已有此数据则不予插入。第一种方法select * from TA_TRL_GO_COMEBILL A left join ( SELECT S_BOOKORGCODE,S_MSGID,S_BNKNO FROM TA_TRL_HVPS_COMEBILL ) B on a.S_BNKNO = b.S_
开发过程遇到 两张表字段相同,但是需要将旧表数据插入新表,如果新表已有此数据则不予插入。
第一种方法
select * from TA_TRL_GO_COMEBILL A left join (
SELECT S_BOOKORGCODE,S_MSGID,S_BNKNO
FROM TA_TRL_HVPS_COMEBILL
) B on a.S_BNKNO = b.S_BNKNO and a.S_MSGID = b.S_MSGID where b.S_MSGID is null
第二种方法
merge into TA_TRL_GO_COMEBILL as a
using (
SELECT S_BOOKORGCODE,S_MSGID,S_BNKNO FROM TA_TRL_HVPS_COMEBILL
where S_PAYERNAME like '%财政%' ) as b
on a.S_BNKNO = b.S_BNKNO and a.S_MSGID = b.S_MSGID
WHEN NOT MATCHED THEN
INSERT (S_BOOKORGCODE,S_MSGID,S_BNKNO)
VALUES (b.S_BOOKORGCODE,b.S_MSGID,b.S_BNKNO)
更多推荐
所有评论(0)