我需要将IF EXISTS Then UPDATE Else INSERT
添加到以下查询中:
-- Exist
UPDATE TargetTable
SET ColumnD = '...', ColumnE = '...'
WHERE ...
-- Doesn't Exist
INSERT INTO TargetTable
SELECT ColumnA, ColumnB, ColumnC, ColumnD, ColumnE, ColumnF, ColumnG
FROM (SELECT DISTINCT ColumnB, ColumnC from SourceTable) derived_table
WHERE ColumnB = 'a';
注意: 由于数据的性质,Source
和Target
表都没有PK
。