473,388 Members | 1,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Discerning unmatched query from multiple tables

I currently have an unmatched query running for multiple tables, however I would like to view which field(s) are different at a glance.

The background here is that I am trying to create a new database combining data from different departments and a separate company. With so many columns, when there is a typo or conflicting data in only one block I have the entire customer row flagged, resulting in searching for the differences by hand.

I am also looking for a better method to convert and equate the differences from the tables at the same time. One table has the full customer name, while the others split it up. Some tables have product codes while others have product names.

What is the best method to attack this project using Access 2007? Additionally time permitting I would like to create a Form frontend to choose if I want to overwrite existing customer data with data from tables imported from a different company?
Nov 15 '11 #1
17 3441
ADezii
8,834 Expert 8TB
Initially, it appears as though you would have a real challenge on your hands, but first a couple of questions.
  1. Does each Table have a Unique Field/Primary Key, and is the Field common to all Tables? I am looking for something like an EmployeeID based on an individual's SSAN, that exists in all the Tables.
  2. Does each Table have the same number of Fields, and are you comparing Values in ALL of the Fields?
  3. Does each Table contain the same Number of Records?
  4. Posting some Sample Data, along with Table/Field Names wouold be very helpful.
Nov 15 '11 #2
1. Yes I do have the common field in all tables which are related.
2/3. No, none of the tables have the same number of column fields or rows of customers. While my focus is currently on 2 tables that I am trying to merge there is even another table that will need to flag (or delete) the customer in the single resultant table.

Field names from the seperate company does not match the field names in my company's tables. Also some of the data that I need to compare is abreviated in one table and not in a seperate table that need to be compared as well.
Nov 16 '11 #3
4. Here is the sample data:
Internal Table
SSN,FirstName,LastName,MiddleInit,Date,Description ,Code
123-456-789,John,Doe,M,11/16/2011,Pen,Accounting

External Table
"Company Code","Formatted SSN","Formatted Name","Date","Description"
"123456","123-456-789","DOE, JOHN MIDDLE",2011-11-16 12:00 AM,"P"

Delinquent Table
"Formatted SSN","Formatted Name","Delinquent Date","Reason","Company"
"123-456-789","DOE, JOHN MIDDLE",2011-01-19 10:17 AM,"Bad Check","123456"

Company Code 123456 is equal to only Accounting in this example.
When I import the External and Delinquent CSVs and set the Data Type for the Date as Date then it errors out and resultantly the Data Type has to be set as a text field.
There are more fields from more tables that I use to complete the final data table/query.
The Code for Pen could have multiple abbreviations from P to Pn or XYZ
Nov 16 '11 #4
ADezii
8,834 Expert 8TB
Kevin, I see no easy Method of Field comparisons across Tables that have different Field Names, Number of Records, etc. I do, however, have an idea but one more question. The Social Security Number exists in every Table, is Unique to each Table, and is stored exactly the same in every Table (XXX-XX-XXXX), is this correct?
Nov 16 '11 #5
Yes SSN is formatted exactly the same in all tables and is in every table.
Nov 16 '11 #6
ADezii
8,834 Expert 8TB
  1. What Field would you like to do an initial comparison on, and what are some of the Values displayed in this Field? I'm thinking initially of something like comparing the [FirstName], [LastName], and [MiddleInit] Fields in the Internal Table to the [Formatted Name] Field in the External Table Linked by SSN.
  2. Do you wish simply to perform the comparison, or change the manner in which the Field is displayed, such as parsing the [Formatted Name] Field in the External Table to [FirstName], [LastName], and [MiddleInit] Fields?
Nov 17 '11 #7
sierra7
446 Expert 256MB
Kevin
My 5 cents of advice is;

You have to plan these data migrations sytematically. They should be totally repeatable and this is particularly true if your source data is still in use and subject to change.

I create myself a new database called, say DataMigration.mdb. I would then import the table structure of your final application, without any data.
I then organise myself an unbound form, as a control panel, onto which I will place groups of command buttons. Each button fires off a query or series of queries, which have been build, tested, named and saved.

The first set of buttons might be to import the data from your standard operation. You will have to link to those tables so you may have tblCustomers and tblCustomers1 for instance. The append queries are very easily created in the query design grid, so this does not take up a lot of time.

You will also need a Reset button that deletes data out of your local tables so you can repeat the import operations easily.e.g.
Expand|Select|Wrap|Line Numbers
  1. Application.SetOption "Confirm Action Queries", False
  2. DoCmd.RunSQL "DELETE * FROM tblCustomers;"
  3. DoCmd.RunSQL "DELETE * FROM tblCustomerAddresses;"
  4. DoCmd.RunSQL "DELETE * FROM tblSalesOrders;"
  5. DoCmd.RunSQL "DELETE * FROM tblSalesOrderDetails;"
  6. ....
  7.  
When you are importing data from your 'External' tables, the important thing is to leave the source data intact. Again, I would recommend that you start by bringing in the structure only, then create queries to append the data to your main tables. One advantage for doing this is that you can then add additional columns to the local table, which will assist in intermediate processing the data to your standard format.

For instance, you might want to run a query that expands 'P' to 'Pen', then a subsequent queries converting 'I' to 'Ink' or whatever. Also, Date-fields from DOS text systems may have different formats within the same column, and Access which is normally very good, may need more than one query to sort out all the options. It's easier to run sequences of saved named queries under a single command button than to try and create and debug a single query with nested IIF()'s.... no-one will ever know!

I also add text boxes that display number of records processed at various stages, so I can check all is running as expected.

Designing a Control Panel probably sounds like a lot more work but it ensures systematic processing and removes the risk of omitting any steps. When it's finished you can add a command button that calls each of the others in sequence, then sit back and enjoy!
It is also essential to reduce downtime when migrating live systems.
S7
Nov 17 '11 #8
NeoPa
32,556 Expert Mod 16PB
I would say, as someone who's had a fair bit of experience in such things, that Sierra7 sounds like he has some too. Worthwhile advice and worth the extra 3 cents ;-)
Nov 17 '11 #9
ADezii
8,834 Expert 8TB
sierra7 does provide some excellent advice and insight into this long and tedious process. I was thinking more along the lines of keeping the original Source Data in tact, but just expanding it. A case in point would be the [Formatted Name] Field of the External Table which consists of the Last, First Name, Middle Initial/Name. I would then add 3 Fields to the External/Imported Table, namely: [First], [Last], [MI]. Next would be parsing the [Formatted Name] Field, then populating the [First], [Last], and [MI] Fields. I do realize that this approach is not foolproof, but it would break down/update the Source Data into some kind of Standardized Format, while still maintaining the Source Data. I like the idea of keeping the Source and Modified data under one roof. Make sense, or not?
Nov 17 '11 #10
sierra7
446 Expert 256MB
NeoPa,
Two cents was the charge when it was five bob to the dollar!
Things have changed. We must be business like now!
S7
Nov 17 '11 #11
NeoPa
32,556 Expert Mod 16PB
Five bob to the dollar? You're talking a Crown in old money. If you're going back that far it should probably be more than five cents by now. Good advice anyway :-)

BTW Did I mention that ages you :-D (But I won't tell a soul.)

PS. Let me say here that my recommendations for Sierra's comment was in no way intended as any sort of criticism of ADezii's efforts, which I'm sure were also very pertinent. My comment was from a position of experience such that I know how many real 'bite you in the bum' situations can occur in the sort of migration project the OP was asking about and I felt that Sierra7 indicated he'd had similar experiences himself. Not many could be expected to have had such experience so ADezii's ideas can still be, and probably are, very helpful.
Nov 17 '11 #12
I'm sorry that I don't know SQL that well, so I don't know what the sample SQL provided above will do exactly. While right now I am running an unMatched query I can see that there is a change for the customer somewhere.
Is there any way of being able to generate a report that will highlight the differences of only the fields that have changed? How much more difficult would it be to have a form with data from 2 tables so that I see a pair of rows for each customer with red borders around the boxes that are different and a check box, drop down, or some way of manually specifying which value is good?
I am fine with comparing my internal live database to each external database one at a time to update the internal database. I am just trying to go about this in the most round about method or is this simple enough (with the limited knowledge I have) and most importantly viable as well?
Nov 18 '11 #13
sierra7
446 Expert 256MB
Hi
To arrange data side by side in a form to compare for differences is relatively simple using a Form/Sub_Form arrangement.

Clearly the two tables being compared must have a field common to both. It can have a different fieldname but hold the same data. It should be unique.

Create two seperate forms which display the fields to be compared. Other fields can be shown too if it helps you.

Open the form which you think represents the 'master' table in Design Mode and then add the second form to it as a Sub-Form. You will have to set the 'Link Master Form' and 'Link Child Form'settings to the appropriate joining fields.

I would then save and run the form and use the navigation control at the foot of the master form to check that the data is synchronized.

If all is OK, go back into Design mode and add somrething like the following code to the On_Current event of the sub-form.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.  
  3. If Trim(Me!Field1) <> Trim(Me.Parent!FLd1) Then
  4.     Me.Field1.BackColor = vbRed
  5. Else
  6.     Me.Field1.BackColor = vbWhite
  7. End If
  8.  
  9. If Me.Field2 <> Me.Parent.Fld2 Then
  10.     Me.Field2.BackColor = vbRed
  11. Else
  12.     Me.Field2.BackColor = vbWhite
  13. End If
  14.  
  15. If Me.Field3 <> Me.Parent.F3 Then
  16.     Me.Field3.BackColor = vbRed
  17. Else
  18.     Me.Field3.BackColor = vbWhite
  19. End If
  20.  
This will change the BackColor of any field tested in the sub-form to Red, that does not match the equivalent field in the master form. Those fields are referenced by 'Parent' and their name in themain form; note their field named do not have to match.

Don't omit the 'Else' statements because the boxes will not automatically turn back to white without them.

When comparing string values it is sometimes necessary to use the Trim() function to remove unwanted leading or trailing spaces.

I hope this helps
S7
Nov 20 '11 #14
sierra7
446 Expert 256MB
Kevin,
I've re-read your post and it seems you may prefer to have the data presented in a report rather than a form.

The same method applies, create a main report and a sub-report. For the SUB-REPORT delete all the labels in headers & footers etc and set their heights to zero.

Instead of using the On_Current event (as required for a Form) select the Detail section of the report, then find the On_Paint event. Insert code like the following;
Expand|Select|Wrap|Line Numbers
  1. Private Sub Detail_Paint()
  2.  
  3. If Trim(Me!Field1) <> Trim(Me.Parent!Field1) Then
  4.     Me.Field1.BorderColor = vbRed
  5. Else
  6.     Me.Field1.BorderColor = vbWhite
  7. End If
  8.  
  9. If Me.Field2 <> Me.Parent.Field2 Then
  10.     Me.Field2.BorderColor = vbRed
  11. Else
  12.     Me.Field2.BorderColor = vbWhite
  13. End If
  14.  
  15. If Me.Field3 <> Me.Parent.Field3 Then
  16.     Me.Field3.BorderColor = vbRed
  17. Else
  18.     Me.Field3.BorderColor = vbWhite
  19. End If
Make sure the BorderStyle = Solid and Border Color = #FFFFFF (white) and then you will find that the fields which differ in the Sub-Report will have a Red border.

I will try and attach an example of the output and then post separately how you might adjust the data.
S7
Attached Files
File Type: zip rptTable1.zip (82.5 KB, 93 views)
Nov 20 '11 #15
sierra7
446 Expert 256MB
PROBLEM WITH LAST POST!
In my last post I suggested that the code should go into the On-Paint event. This is because I was using Access 2010 but I noticed that the red boxes sometimes appeared when they should not have, until I clicked on them!

This was unusual so I exported the demo to Access 2003 and put the code in the On_Format event and everything works fine.

I've read that Access 2010 does interactive reports but I did not take notice because for me, a Report is a piece of paper and anything interactive is a Form.

Back to school!
S7
Nov 20 '11 #16
sierra7
446 Expert 256MB
In my last post I reported that I had encountered a problem with the way the report formatted the data.

I have now found that the report works perfectly when called from a command button but exhibits some 'interactive' behaviour when opened by double clicking in the Database Window.

I'll raise this as a separate thread "Why does Report Open Interactively?" if I can't resolve the matter
S7
Nov 23 '11 #17
NeoPa
32,556 Expert Mod 16PB
Please post a link in here in case I miss it S7.

It's fun watching you contradict yourself (I mean learn as you go) :-D

PS. It's also new to me so I'm not watching from ahead of you.
Nov 23 '11 #18

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Ralph Guzman | last post by:
TASK: I have to generate a report with all categories, subcategories and products in database. PROBLEM: I want to write one query that will return: 1. category 2. subcategory: determined by...
8
by: Rigga | last post by:
Hi, I am new to mysql and need help on how to join tables. I have a database which contains 4 tables, the main table contains information by date order and the other 3 contain data also in date...
2
by: sal cifone | last post by:
Hello, I am trying to use access vba instead of running an unmatched query. I want to compare two tables and if there is a new sales office in "Commissions" table that is not in the "Conversion"...
1
by: Brian | last post by:
I have 2 questions, the first is probably simple. Let's say I have an employee table listing all employees and a sales table listing employees that have made sales. How can I create a query to...
8
by: Mark Welch | last post by:
I am at a complete loss on how to do this. I am using Microsoft Access 2000, to implement a preliminary version of a reasonably modest relational database. I have two Access Tables (imported...
0
by: djflow | last post by:
Hi! II was wondering if you can help me with SQL query.. Below 7 separated select query works fine(only when they are retrieved separately) But I want to combined them together and so that i...
5
by: themastertaylor | last post by:
I've got a system to manage various quotes for building materials for a number of sites. i want a query to produce a report that shows me who HASN'T quoted for which sites. basically so i can...
1
by: rfranzl | last post by:
Hello, I need some help, I have about 200 databases that are copies of an original database that has a similiar table in all of the databases, called "tblCodebook". What I am trying to do is to...
1
by: lawardy | last post by:
Hi, I'm quite new with Reporting server 2005. I'm wondering if there is a way to write a select query that will get the data from 2 diffrent tables located in 2 diffrent database box. for...
1
by: Tlou5831 | last post by:
I am attempting to compare 2 tables in my DB and find unmatched criteria. There are 2 different fields in each database that need to be compared. Tbl_AppUsers Role Settings INQ ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.