Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 using merge?

Author  Topic 

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2012-02-27 : 09:04:18
I have two sql tables in the same db with identical structures. My desire is to take the records from mnitwo and insert them to mnione. There are no entries in mnione which exist in mnitwo, therefore no chance for duplication or the need to set conditions for 'if exists' of any kind. My question is, would i use the "merge" statement to get this done? using SQL 2008R2.

thanks.

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2012-02-27 : 09:09:25
why would you use merge if you know there is no overlap?

Simply INSERT .... SELECT ....

You'd use MERGE if there is a possiblity of a match and then have a WHEN MATCHED BY source (with an update) and a WHEN NOT MATCHED (insert) clause.

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2012-02-27 : 09:24:33
was trying that and getting a table definition mismatch error. i've since found the difference in structures between the two and the regular insert worked.

thanks
Go to Top of Page
   

- Advertisement -