if exists, update, else insert new record

Posted by I__ on Stack Overflow See other posts from Stack Overflow or by I__
Published on 2010-06-07T18:53:56Z Indexed on 2010/06/07 19:02 UTC
Read the original article Hit count: 197

Filed under:
|
|

i am inserting values into a table

if the record exists already replace it, and if it does not exist then add a new one.

so far i have this code:

INSERT INTO table_name
VALUES (value1, value2, value3,...) where pk="some_id";

but i need something like this

if not pk="some_id" exists then  INSERT INTO table_name
    VALUES (value1, value2, value3,...) where pk="some_id"; else update table_name where pk="some_id"

what would be the correct SQL syntax for this?

please note that i am using sql access and that i guess it can be a combination of vba and sql

© Stack Overflow or respective owner

Related posts about sql

Related posts about ms-access