Originally posted by chrisrlong
Which, as I said, is simply in the wrong order You don't want to insert the records *before* the update, or you will end up updating those very same records (as well as the others), right? You always do the update before the insert. My next post was only applicable if bulk statements could not be done, as I specified at the beginning of said post.
Ok now I get you, yes ofcourse Update then Insert should be performed, else unneccesary updates.



Originally posted by chrisrlong

Okay, so in my haste, I went a *little* too far, but not by much.
Code:
INSERT -- TEST02
INTO JUNK
SELECT * from JUNK WHERE PK = 1

INSERT -- TEST02
INTO JUNK
SELECT * from JUNK WHERE PK = 1
AND NOT EXISTS(SELECT 1 FROM JUNK WHERE PK = 1)
Compare the buffer gets on the two statements. The second one is much more efficient. Therefore, If more inserts:

INSERT WHERE NOT EXISTS
IF SQL%ROWCOUNT = 0
THEN
UPDATE...

However, the same does not appear to apply to updates

In this case, both statements run exactly the same.
So, if more updates, simply:

UPDATE ...
IF SQL%ROWCOUNT = 0
THEN
INSERT...

- Chris
Ultimate!!
Now, it wud be interesting to see Jurij's reply