Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Append or Update Query

Posted on 2014-10-04
3
Medium Priority
?
180 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
[X]
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
3 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 1000 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 48

Expert Comment

by:Dale Fye
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 51

Assisted Solution

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

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

670 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