SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 using merge?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

WJHamel
Aged Yak Warrior

USA
614 Posts

Posted - 02/27/2012 :  09:04:18  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

United Kingdom
3425 Posts

Posted - 02/27/2012 :  09:09:25  Show Profile  Visit Transact Charlie's Homepage  Reply with Quote
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

USA
614 Posts

Posted - 02/27/2012 :  09:24:33  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000