Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Append or Update Query

Posted on 2014-10-04
3
169 Views
Last Modified: 2014-10-05
I want to run a query that updates a record I a table if the record already exists.   But if the record does not exist I want it to create a new record in the table.

The source table is "Source".  The destination table is "Destination"

The both have a key field named "RecordID"

If I just try to run an update query it fails because the record isn't there.  But if I run an append query it works fine if the record is already there.

Confused!!

--Steve
0
Comment
Question by:SteveL13
3 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 250 total points
ID: 40361418
this can be done by using a Left join instead of an Inner join in your update query


update source LEFT JOIN destination
ON source.recordid = destination.recordid
SET destination.[field1] = [source].[field1], destination.[field2] = [source].[field2], destination.[field3] = [source].[field3];
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 40361494
What Rey said!  (no points please)

Some people call this an UPSERT query.  In SQL Server, they have a similar query syntax called MERGE which gives you the ability to Update and Append at the same time, and you can even get a count of how many of each action are completed.
0
 
LVL 49

Assisted Solution

by:Gustav Brock
Gustav Brock earned 250 total points
ID: 40361573
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question