MERGEINTO target AS C2 USING source AS C1 ON C2.id = C1.id WHEN MATCHED THEN UPDATESET C2.country = C1.country, C2.city = C1.city WHENNOT MATCHED THEN INSERT (id, country, city) VALUES (C1.id, C1.country, C1.city);
(4).SQLServer执行结果
(5).hgdb执行报错
解决方案
(1).修改语句
begin UPDATE target set country = C1.country,city=c1.city from (select id,country,city from source) C1 where target.id = c1.id; insert into target(id,country,city) select*from source as c1 wherenotexists (select id from target where id = c1.id); end;