Link to home
Start Free TrialLog in
Avatar of earwig75
earwig75

asked on

Skip insert in SQL if duplicate exists.

I want to skip or ignore an insert if the values already exist in the table. Below is the SQL I am trying to use but it doesn't seem to work. Can someone assist? I am filling in the values, but they are normally entered by variables in my application and this query is in a loop... that's why I want to ignore if a duplicate exists. Thank you.

INSERT INTO myTable
                  ([ID],[theName],[Auth],[LastModifiedBy])
            VALUES(
                  5
                  ,hello
                  ,yes
                  ,bob
                  )      
            WHERE hello
            NOT IN      (SELECT [ID], [hello]
                         FROM myTable
                         WHERE ID = 5
                         AND AccessID = hello
                  )
ASKER CERTIFIED SOLUTION
Avatar of Jim Horn
Jim Horn
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
SOLUTION
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