insert IF record doesn't exist

J

Julia Lerman

Can a conditional insert query be constructed in Access? I know I can do
this in sql stored procs, I know I can code it up in VBA, but I have a
friend who is determined to do the whole thing as a query. I even sent him
the VBA code for a module, but I think he will need a lot of lessons to
implement that.

The condition is to search for a particular record by it's id. If if does
nto exist (count returns 0 or however), then go ahead and do an insert.

tia
 
J

John Vinson

The condition is to search for a particular record by it's id. If if does
nto exist (count returns 0 or however), then go ahead and do an insert.

Base the Append query on an unmatched query using the target table:

INSERT INTO targettable (<blah blah>
SELECT <blah blah>
FROM sourcetable LEFT JOIN targettable
ON sourcetable.ID = targettable.ID
WHERE targettable.ID IS NULL;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top