There are a number of questions on the proper use of the MERGE statement in SQL Server. They all use a table/set reference for the merge. Is this table reference necessary?
In my case I have a sproc with two parameters @myId and @myValue
I simply want an UPSERT into MyTable based on the column [MyId]
It seems strange that I would have to create a set with
USING (SELECT @myId AS myId) AS source
to proceed with the MERGE (upsert). Is this the only way?
EDIT: voted to close my own question as exact duplicated... but I think the other question's title made it difficult to find.
UPDATE / IF @@ROWCOUNT = 0 / INSERTis much easier to write, maintain, and understand. IMHO.MERGEin sprocs is faster to process thanUPDATE / IF @@ROWCOUNT = 0 / INSERT... Both links you provide are good, though neither apply to my particular use case.MERGEfunction (perhaps they are not aware of the limitations you've discovered).