Importing csv file / unique records

Lady Phoenix

Registered User.
Local time
Today, 11:35
Joined
Jan 19, 2015
Messages
10
As you can see from my profile Im new here, so if this question is stupid, or been asked before, please go easy on me :)

I need to import a .json file into my access database. Ive looked at all the info on the web and with my current skill level its far too complicated for me, so I use this site

https-colon-//json-csv.com/

and then import the data as a csv file. Slightly fiddly but not a problem

So, I import the file into my database but what I would like to do is have the database check for unique records. If the record already exists in the database I want it to overwrite the old info with the latest info. Otherwise it can just create a new record. Im not fussed about old records being deleted at this stage.



Background - Im looking to import player data from a football game. For example, this team
Cant post links I have 3 posts
data is held here
Cant post links I have 3 posts

The file contains player info and from that I can calculate how to train a player by using the numbers for each ability. Each player is assigned his own ID number which I will use as a "non duplicate" field.
 
You can't do what you want as a direct import.

What you will need to do is to import the data into a temporary table and then use an update query to import data where there is a difference between the 'old' record and the new

You will need a unique field or fields to be able to identify a specific record

So for this example, I've assumed the unique ID is playerID and all field names and types are the same in each table (3 fields).

Code:
 UPDATE dbTable INNER JOIN tmpTable ON dbTable.playerID=tmpTable.playerID
 SET dbTable.fld1=tmpTable.fld1, dbTable.fld2=tmpTable.fld2, dbTable.fld3=tmpTable.fld3
 WHERE dbTable.fld1<>tmpTable.fld1 OR dbTable.fld2<>tmpTable.fld2 OR .dbTable.fld3<>tmpTable.fld3
And then you need to run an append query to append records which do not already exist...

Code:
 INSERT INTO dbTable (PlayerID, Fld1, Fld2, Fld3)
 SELECT tmpTable.PlayerID, Fld1, Fld2, Fld3
 FROM tmpTable LEFT JOIN dbTable on tmpTable.playerID=dbTable.playerID
 WHERE dbTable.playerID is NULL
 

Users who are viewing this thread

Back
Top Bottom