dbTalk Databases Forums  

update/apphend Fkey on Import

comp.databases.ms-access comp.databases.ms-access


Discuss update/apphend Fkey on Import in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
flebber
 
Posts: n/a

Default update/apphend Fkey on Import - 01-23-2011 , 06:49 AM






If I have a table of excel data that I will be consistently importing
with new data. The acccess table I will be importing into has an
foreign key for two fields name and location. If the name and location
doesnt exist what is the best method to ensure that the new data is
updated to its main table?

Reply With Quote
  #2  
Old   
John Spencer
 
Posts: n/a

Default Re: update/apphend Fkey on Import - 01-24-2011 , 08:20 AM






Well, we lack quite a bit of information about table structure.

In general, I would import the data into a work table (or set a link to the
Excel "table" and then use an append query to add new records to the table
(SomeLocationTable0 that contains the values for location and name.

INSERT INTO [SomeLocationTable] ([Name],[Location])
SELECT Temp.Name, Temp.Location
FROM WorkTable as Temp LEFT JOIN [SomeLocationTable]
ON Temp.Name = [SomeLocationTable].Name
AND Temp.Location = SomeLocationTable.Location
WHERE SomeLocationTable.Name is Null

This assumes the the Primary Key in SomeLocationTable is autogenerated (it is
an autonumber).

Then after the above runs you import the records from the WorkTable into your
destination table.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

On 1/23/2011 7:49 AM, flebber wrote:
> name and location

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.