Last post Dec 01, 2020 01:18 PM by imapsp
Dec 01, 2020 06:57 AM|demoninside9|LINK
I need to transfer some of columns data from from one table to another.
I can do it easily using the below query
(column1, column2, column3, ...)
column2, column3, ...
Here I have a condition, that id the mentioned columns data already exists in table2 then it should update the data otherwise it should insert the remaining data which is not exists in table2 and I don't want to
use any external parameter for that.
Dec 01, 2020 01:18 PM|imapsp|LINK
I believe you can use the Merge statement:
MERGE table2 as t2
USING table1 as t1 ON t1.Id = t2.Id
WHEN MATCHED THEN
UPDATE SET t2.column1 = t1.column1, t2.column2 = t1.column2, t2.column3 = t1.column3
WHEN NOT MATCHED THEN
INSERT (column1, column2, column3)
VALUES (t1.column1, t1.column2, t1.column3)
Hope this help