简体   繁体   中英

SQL Server : openquery insert linked server

How do I insert data into a linked server (oracle) with a condition that a row does not exist?

I want to insert into employee table if employeecode does not exist yet in that table

INSERT INTO OPENQUERY(ORACLEX,
  'SELECT EMPCODE, EMPNAME FROM AX.EMPLOYEE') -- I want a where clause here

Select EID, ENAME FROM EMPDATA

You might actually have to read from the table twice

   INSERT INTO OPENQUERY(ORACLEX,
  'SELECT EMPCODE, EMPNAME FROM AX.EMPLOYEE') -- I want a where clause here
   Select D.EID, D.ENAME
     FROM EMPDATA D
LEFT JOIN OPENQUERY(ORACLEX,
  'SELECT EMPCODE, EMPNAME FROM AX.EMPLOYEE') OQ ON OQ.EMPCODE = D.EID
    WHERE QQ.EMPCODE IS NULL;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM