Update table with new records from Excel file (1 Viewer)

tmyers

Well-known member
Local time
Today, 07:08
Joined
Sep 8, 2020
Messages
1,090
I am trying to maintain my customer list (tblCustomers) and adding in new accounts from an excel file exported from our main DB. I imported the file into a temp table, but for the life of me can't remember how to append only new records from the temp table to the permanent table. Can one of you wonderful people offer guidance? :)

For the record, for various reasons I am unable to use the excel file as a linked table and just overwrite it when an update is needed.
 

tmyers

Well-known member
Local time
Today, 07:08
Joined
Sep 8, 2020
Messages
1,090
Remembered how to do it. Made an unmatched query then used that query to append the new records to the table. Guess I just needed a few more drinks of coffee!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:08
Joined
May 7, 2009
Messages
19,234
a single typo error can cause unmatch query to include it even when the account already exists.
 

tmyers

Well-known member
Local time
Today, 07:08
Joined
Sep 8, 2020
Messages
1,090
That is fair. I am basing the unmatched on account numbers which are main DB generates and are unique and are not reused.
 

tmyers

Well-known member
Local time
Today, 07:08
Joined
Sep 8, 2020
Messages
1,090
To slightly add to this, how can I update a column with data from another column in the same table?

With the same data I just updated to add in new accounts, I also added in an account lookup column, this column will almost always contain the same number as the account #, but in a couple instances (like 50 out of nearly 2k) the number will be different.
I already set those 50 to what they need to be now I just need to mass update column LookupAccount to equal Account# where LookupAccount is either 0 or null. How would that query work? I have never updated a table using itself and I really don't want to spend the next 2 hours manually entering nearly 2 thousand account numbers :ROFLMAO:
 

Gasman

Enthusiastic Amateur
Local time
Today, 12:08
Joined
Sep 21, 2011
Messages
14,269
Well you just said the criteria yourself?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:08
Joined
May 7, 2009
Messages
19,234
Update [yourTableName] Set [LookupAccount] = [Account#] Where Nz([LookupAccount], 0) = 0;
 

tmyers

Well-known member
Local time
Today, 07:08
Joined
Sep 8, 2020
Messages
1,090
In the query editor would I just set the field then in the update to make it say, tblCustomer.Account# and criteria ISNull OR 0?

Edit:
Ah, so it is that simple
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 19:08
Joined
May 7, 2009
Messages
19,234
copy and paste the query i post in SQL view.
then edit the tablename and the fieldnames to the correct one.

Nz([LookupAccount], 0) = 0, means same thing (Is Null or 0).
 

Gasman

Enthusiastic Amateur
Local time
Today, 12:08
Joined
Sep 21, 2011
Messages
14,269
In the query editor would I just set the field then in the update to make it say, tblCustomer.Account# and criteria ISNull OR 0?

Edit:
Ah, so it is that simple
I tend to make it a Select query first, to make sure I am updating what I think I should, then change to update.
I also take a copy of the table first, just in case. :)
 

Users who are viewing this thread

Top Bottom