1

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
3
  • why did you tag sql-server if you want an oracle solution? Commented Nov 15, 2012 at 5:02
  • This is a sqlquery, i am running it in MSSQL server just connecting to linked server. Commented Nov 15, 2012 at 5:09
  • 1
    Nobody knows the answer?? Oh God please help!!!! Commented Nov 15, 2012 at 11:35

1 Answer 1

3

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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.