There are various times when it is useful to be able to compare the data in two or more separate records from the same table. For example when you have imported a change to a record, you should make a copy of it before you run your import which you can then use to compare with the same record after the import.
To make a copy before your import, you can either copy the data Java Client and paste it into a spreadsheet, or run a sql query of the form:
select * from table where keyfield = 'NameOfRecord'
and paste the output into a spreadsheet. The advantage of the second method is that you capture all of the data in the record, and not only what is allowed by the mdl controlling the Java Window.
A good practice is to put the data you capture into a worksheet of the file containing the source for your import. Name the tab something along the lines of “pre-import data”.
Once you have run your import, you can use the same method to capture the data once more, and paste it into the source file in a new worksheet called (for example) “post-import data”.
Whatever else you do with this file, it now acts as a record of what change(s) you made, when (if you follow my file-naming convention), and the state of the data before and after the import.
Comparing the two sets of data
I use two different ways of comparing data, depending upon its volume.
For individual or small numbers of records:
- Paste the two sets of data into a temporary spreadsheet, one above the other.
- Highlight both records – select cell A1 and hit Shift-Ctrl-End – and Ctrl-C to copy them.
- Highlight the first cell – ie in column A – in the empty are below the data.
- Select Paste Special, and use the Transpose option. This will paste both records vertically side-by-side.
- Select AutoFilter on.
- Delete all the rows above your newly-pasted columns of data.
- Insert a blank column between the two records.
- In the top row of the blank column, enter the function =B1=E1 (adapt this function to the cell references of your actual data – I am assuming your source data consists of one row of field names and a one row of data).
- Copy the function and paste it in the same column all the way down to the bottom of the data.
- Using the autofilter deselect the value TRUE from view.
Whatever lines are left will show you changes made to the data.
For large volumes of data
This method assumes you have a file with two worksheets containing your pre-import and post-import data. The data should be arranged in the same order in each sheet – ie copied from the system in exactly the same order of rows and columns, and pasted into the same range in the worksheets.
- Create a new worksheet in the file containing your pre-import and post-import worksheets.
- In cell A1 put the formula
='pre-import data'!A1='post-import data'!A1
adapt the cell references if you have used different names for your worksheets.
- Copy A1 and paste it into the same range as covered in the data worksheets.
- The comparison worksheet will show you the cell references where there is a difference between the two data sets.
To increase the utility of this method, you can use conditional formatting to highlight the FALSE cells.
To increase the utility further, use the formula below, which will show you the two values side-by-side where they are different
=IF('pre-import data'!A1='post-import data'!A1,1,'pre-import data'!A1&" : "&'post-import data'!A1)
As a final refinement, the first row of data in your pre and post sheets should contain the field names of the columns. If you post this first row into your checking worksheet, you can see instantly what column the changed data is in.