I have 2 table one is a Stage table whose schema is exac to main,i want to update the data from stage table to main table with the ID column as refrential key. I have tried using Merge in SQL but facing problems with that as there are only few values to be updated and thousand of new values need to be inserted to the main table. e.g:
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
(
----I am stucked here what to write as there are thousands of values:(
)
You can refer to the merge source in the
insert
part, like: