I need to add IF EXISTS Then UPDATE Else INSERT
to the following queries:
-- 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';
NOTE: Both Source
and Target
tables have no PK
due to the nature of data in it.
EDIT: the "duplicate" question/answer doesn't work for me because my tables has no primary keys.