Link to home
Start Free TrialLog in
Avatar of gary_j
gary_jFlag for United States of America

asked on

conditional insert using exists (AGAIN!)

This statement returns an "Incorrect syntax near the keyword WHERE" error, and I don't understand why ...

INSERT INTO atable VALUES (list of column values) WHERE NOT EXISTS
      (SELECT * FROM thesametable WHERE col_1 = 'something' And col_2 = 'somethingelse')

I know it has something to do with EXISTS; I confirmed that by removing the WHERE clause from the SELECT statement.

ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Or you can do this:

INSERT INTO atable
SELECT (list of column values)
WHERE NOT EXISTS(SELECT * FROM thesametable WHERE col_1 = 'something' And col_2 = 'somethingelse')
Avatar of gary_j

ASKER

thank you very much!