How to use the merge command

Posted by Vaccano on Stack Overflow See other posts from Stack Overflow or by Vaccano
Published on 2010-06-16T20:07:35Z Indexed on 2010/06/16 20:12 UTC
Read the original article Hit count: 148

Filed under:
|
|

Say I have a table called Employee (has ID, NAME, ADDRESS, and PHONE columns). (Not my real problem, but simplified to make the question easier.)

If I call a sproc called UpdateEmployee and I pass in a @Name, @Address, @Phone and @ID.

Can merge be used to easily check to see if the ID exists? If it does to update the name, address and phone? and if it does not to insert them?

I see examples on the net, but they are huge and hairy. I would like a nice simple example if possible.

(We recently upgraded to SQL 2008, so I am new to the merge command.)

© Stack Overflow or respective owner

Related posts about sql

Related posts about tsql