Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 126
  • Last Modified:

Access 2016 Merge Tables

I am attempting to create a database that combines information from 2 sources.  One is a time keeping system, Table A.  The other is from a payroll system TableB.

I want to create a new table that uses all the data in Table A and and adds the SSN and ITemID from Table B.  Two fields in Tables have to match.  EmID from Table A has to match AIdent from Table B.  Also Worked Department from Table A has to match DeptName in TableB.

I have to match multiple fields because some employees will work in multiple departments in a single pay period.

I've tried using Dlookup and I can't seem to get the data to merge properly.  I keep getting hundreds of duplicate records.

I'm attaching a sample file with fake data that matches the structure of my real DB.  Didn't want to share anyone's SSN.
Sample.accdb
0
Mwvarner
Asked:
Mwvarner
  • 3
  • 2
  • 2
  • +1
1 Solution
 
aikimarkCommented:
Since you have duplicate people rows in TableB and no way to refine the joining of the two tables, you need to remove the duplicates from TableB.
0
 
aikimarkCommented:
Duplicate removal query
DELETE TableB.*
FROM TableB 
WHERE TableB.ID <> (Select Min(B.ID) From TableB As B
WHere (TableB.FirstName = B.FirstName) AND (TableB.´╗┐LastName = B.´╗┐LastName))

Open in new window

0
 
MwvarnerAuthor Commented:
The rows in Table B aren't completely duplicates.  The departments and assignments are different.   I know DLookup can use multiple criteria I just can't work out the syntax.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
aikimarkCommented:
Unless you can state when one TableB row should be used and when a different TableB row should be used in the table-join operation we can't help you.  I don't see any other columns that help in this process.
0
 
PatHartmanCommented:
We don't have enough information to resolve the problem but as has already been mentioned, you need to eliminate any duplicates.  In both tables, you will validly have multiple rows for a given employee so you should create queries to summarize or group the data to get down to a single row per employee per source.  Then you can join the queries and not end up with nonsense in the output. The problem is caused because neither table is an employee "master".  Both tables are transnational and by definition, will include multiple rows for each employee.

Before you can do any joining, you need to make the data types consistent.  So the department code should be EITHER numeric or text.  I'm going to suggest that it be text unless you know for certain that at the source, it will NEVER contain non-numeric characters and NEVER require leading zeros.  Fields like SSN are NOT NUMERIC.  They may contain only numbers at present but they are CODES and CODES are  always text unless you have a death wish.  SSN can have leading zeros so unless you want to end up with SSN's that are less than 9 characters, you MUST define SSN as text.  Same with Zip CODE if that field is contained in any of your import tables, especially if you might have employees with Canadian addresses.

Using DLookup() is not the correct way to solve this problem.  You shouldn't ever use domain functions in queries especially if there is an alternative and in this case there is.

PS, including ItemID (whatever that is) will prevent tableB from being summarized to one row per employee and once that happens, the joins will always produce nonsense so we are going to need to know more about your ultimate goal to advise further.
0
 
John TsioumprisSoftware & Systems EngineerCommented:
Take a look at my attachment --> FinalJoinedTable (query)
Sample.accdb
0
 
MwvarnerAuthor Commented:
Great Job and I really appreciate the assist. I have posted a related question so maybe you can help with that one as well.

Thanks again.
0
 
PatHartmanCommented:
Look very carefully at the sample output created by John.  It might not actually work the way you need it to but then you never did explain how the de dupe should work.
1

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now