title: Merging 2 tables from different databases using MERGE INTO
body: <p>I would like to use MERGE to merge 2 tables from different databases into one table. Both Databases are on the same server. </p>
  
  <p>Currently, I can do the following: </p>
  
  <pre><code>USE Northwind2
  
  SELECT a.CategoryID 
  FROM Northwind.dbo.Categories a 
  INNER JOIN Northwind2.dbo.Categories b ON a.CategoryID = b.CategoryID
  </code></pre>
  
  <p>However, I need to merge the results into one table. I thought I could do something like this: </p>
  
  <pre><code>USE Northwind2
  
  MERGE INTO Categories B
  USING (
    SELECT E.CategoryID
    FROM Northwind.dbo.Categories) E
  ON (B.CategoryID = E.CategoryID)
  WHEN MATCHED THEN
    //update the table
  WHEN NOT MATCHED THEN
    //insert into the table
  </code></pre>
  
  <p>This will return an error saying the following: </p>
  
  <blockquote>
    <p>Msg 10739, Level 15, State 1, Line 10<br>
    The insert column list used in the MERGE statement cannot contain multi-part identifiers. Use single part identifiers instead.</p>
  </blockquote>
  
  <p>I'm not sure how I would remove the multi-part identifiers and still have this work... since I need to define which database we are looking in. </p>
  
  <p>Any ideas on how I would get around this? Any help would be appreciated </p>