Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

sql query assistance on merge

$
0
0

MERGE tb1 AS Target
USING  (select f1,f2 from tb2) AS Source
ON (Target.[CAS_ID] = Source.f1 =target.f1
)
WHEN MATCHED THEN
      UPDATE SET 
                Target.f2 = Source.f2
                  THEN NOT MATCHED BY TARGET THEN
INSERT (f1,f2)
VALUES (Source.f1,Source.f2)
WHEN NOT MATCHED BY SOURCE and (select id from tb3 where id in (1,2,3))
THEN DELETE
;

What is the issue in this table? I want to delete all rows that doesn't match and also those rows that are there in tb3.


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>