Hi,@sql dev
Welcome to Microsoft T-SQL Q&A Forum!
Step1:I guess you only match one in the on condition. The two tables f and u must have fields that can be matched. You can observe the table when f.id = u.id, there must be many rows that match, so Just got this error.
Step2: More conditions should be inserted to perform one-to-one row matching between tables.
Step3: Modify the code
ALTER PROCEDURE [sp_name] AS
Merge into table1 f
Using table2 u
ON f.id = u.id and f.column=u.column---The matching field is not unique, add a matching field
AND f.[column1] IS NOT NULL OR f.[column2] IS NOT NULL
WHEN MATCHED
THEN
UPDATE set f.[column1] = u.[column1],
f.[column2] = u.[column2],
WHEN NOT MATCHED
THEN
INSERT (column1,column2)VALUES ([column1],[column2])
Best regards,
Bert Zhou
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.