Search code examples
sql-serveropenquery

How to update a SQL Server table with updated Oracle table Data


I am using SQL Server (and Oracle as a linked Server).

The task involves updating the SQL Server table with any new changes to the column NAME in the Oracle TABLE.

EMP is PK and NAME is the column that can change.

ORACLE TABLE = TABLE1:

EMP                  NAME                
-------------------- --------------------
1                    JOE               
2                    David               
3                    BOB    

SQL SERVER TABLE = TABLE1:

EMP                  NAME                
-------------------- --------------------
1                    JOE               
2                    David               
3                    FRED   

Code which is not working (runs and runs w/o updating):

 UPDATE OC 
    SET    OC.NAME = MS.NAME
    FROM   OPENQUERY(ORCL12,
      'select EMP, NAME from TEST1') OC 
         INNER JOIN [dbo].[TEST1] MS 
     ON MS.EMP = OC.EMP

Solution

  • Thanks to @elizabk, here's the answer.

    UPDATE MS 
        SET    MS.NAME = OC.NAME
        FROM   OPENQUERY(WZ12,
          'select EMP, NAME from Test') OC 
       INNER JOIN [dbo].[TEST1] MS 
         ON OC.EMP = MS.EMP
    

    Note: This was originally an edit to the original question. I just moved it here. @elizabk if you want to post your response, I'll delete this one.