I have two tables, one of which is the Stage table, the scheme of which is exac for main, I want to update the data from the stage table to the main table, the identifier column is like a backup key. I tried using Merge in SQL, but ran into problems as only a few values were updated, and thousands of new values needed to be inserted into the main table. eg:
MERGE TABLE tblMain AS main
USING (SELECT ID,NAME,EMAIL_ID FROM tblStage) as stage
ON main.ID=stage.ID
WHEN MATCHED THEN UPDATE SET
main.ID=stage.ID,
main.NAME=stage.NAME,
main.EMAIL_ID=stage.EMAIL_ID
WHEN NOT MATCHED THEN INSERT VALUES
(
)
source
share