Solved

update and insert records

Posted on 2009-05-09
4
223 Views
Last Modified: 2013-11-27
Hello.
I would like to be able to update existing records and insert new records into a main table from another table.

Is this possible using append query to do the inserts and update query to change the data on existing records?

I have been trying to do an append query to append new records into the main table if they don't already exist another table. Then doing an update query to update the existing data in the main table?

How may this be done or is it better doing it with a macro or code

Thanks,
Ivan
0
Comment
Question by:icarey
[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
  • 2
  • 2
4 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24343361
you have to do this with 2 queries.
first, the update based on the join for the existing ones, and then insert those that are not yet in the table.
the update should be easy.
the insert requires a select like this one:
select b.*
  from table b
  left outer join a on (a.key = b.key) 
   where a.key is null

Open in new window

0
 
LVL 3

Author Comment

by:icarey
ID: 24343580
thanks angelIII

I have created the query ok but am unable to insert into the table due to field count

Tables STOCK and stock_new
Field names in both
NAME TITLE NAME2

SELECT stock_new.*
FROM stock_new LEFT JOIN STOCK ON stock_new.NAME2 = STOCK.NAME2
WHERE (((STOCK.NAME2) Is Null));

displays the new records

INSERT INTO STOCK(NAME,TITLE,NAME2)
SELECT stock_new.*
FROM stock_new LEFT JOIN STOCK ON stock_new.NAME2 = STOCK.NAME2
WHERE (((STOCK.NAME2) Is Null));

comes up with an error
Number of query values and destination fields are not the same

0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 24343616
this will do:
INSERT INTO STOCK(NAME,TITLE,NAME2)
SELECT stock_new.Names2, stock_new.Title, stock_new.Names2
FROM stock_new LEFT JOIN STOCK ON stock_new.NAME2 = STOCK.NAME2
WHERE (((STOCK.NAME2) Is Null));

Open in new window

0
 
LVL 3

Author Closing Comment

by:icarey
ID: 31579754
Thank you angelIII your answer has help me greatly

Ivan
0

Featured Post

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
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…

636 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