SQL Server:openquery插入链接服务器

时间:2012-11-15 05:00:39

标签: sql-server linked-server

如何使用不存在行的条件将数据插入到链接服务器(oracle)中?

如果该表中尚不存在employee,我想插入employeecode

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

Select EID, ENAME FROM EMPDATA

1 个答案:

答案 0 :(得分:3)

您可能实际上必须从表中读取两次

   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;