delphi 通过A表批量更改B表的内容
通过Excel导入内容到表A,并显示在dbgrid中,点击批量修改按钮,通过导入表A的内容修改表B。现在有一个问题,导入的这一批内容,如果在表B中不存在,则插入,如果在表B中存在,则更新,如何实现?
[解决办法]
--1、插入:
insert into B
select 字段1,字段2,。。。。。。 from A
where not exists(select 1 from B where A.字段1=B.字段1 and A.字段2=B.字段2。。。。。。)
--2、更新:
update B
set B.字段1 = A.字段1, B.字段2 = A.字段2,。。。。。。
from A
where A.字段1 = B.字段1 and A.字段2 = B.字段2。。。。。。