insert IF record doesn't exist

  • Thread starter Thread starter Julia Lerman
  • Start date Start date
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
 
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;
 
Back
Top