I am trying to compare 2 tables from 2 different databases using ODBC.
After researching the web and the groups I decided to use arrays as
looping through recordsets was painfully slow. My code runs well and I
accomplish my objective to compare what amounts to one table of over
4000 records and a second table of over 2800 records in 37 seconds. I
am happy with the outcome and the results are written to an Access
database with 3 tables showing the differences both ways and where the
data is equal. I am providing the below code as a reference to my
question.

Is there a more efficient way of comparing this data so that I can see
the differences each way and where the data is the same? This is just
the start of a very large project and I will be comparing many tables
across different databases and I am looking to make this as efficient
as possible. Is it possible to compare the data both ways and keep it
to a single loop or is there a more creative solution available.

Thanks for any suggestions.


' Fill Arrays from recordsets
If not Rs_01.EOF then arr_01 = Rs_01.GetRows
If not Rs_02.EOF then arr_02 = Rs_02.GetRows
' Compare Array1 to Array2 where equal add to recordset Rs_PackageEqual
' where different add to recordset Rs_PackageDiffPMA
For x = 0 to Ubound(arr_01,2)
For y = 0 to Ubound(arr_02,2)
If arr_01(0,x) = arr_02(0,y) Then
Rs_PackageEqual.AddNew
Rs_PackageEqual.Fields("Packages") = arr_01(0,x)
Rs_PackageEqual.Update
Exit For
ElseIf y = Ubound(arr_02,2) Then
Rs_PackageDiffPMA.AddNew
Rs_PackageDiffPMA.Fields("Packages") = arr_01(0,x)
Rs_PackageDiffPMA.Update
End If
Next
Next
' Compare Array2 to Array1 where different add to recordset
Rs_PackageDiffPricing
For x = 0 to Ubound(arr_02,2)
For y = 0 to Ubound(arr_01,2)
If arr_02(0,x) = arr_01(0,y) Then
Exit For
ElseIf y = Ubound(arr_01,2) Then
Rs_PackageDiffPricing.AddNew
Rs_PackageDiffPricing.Fields("Packages") = arr_02(0,x)
Rs_PackageDiffPricing.Update
End If
Next
Next
'

Re: Compare 2 tables for matches and differences by McKirahan

McKirahan
Sat Mar 18 10:28:17 CST 2006

"clu" <josperjr@gmail.com> wrote in message
news:1142697254.050035.309170@p10g2000cwp.googlegroups.com...
> I am trying to compare 2 tables from 2 different databases using ODBC.
> After researching the web and the groups I decided to use arrays as
> looping through recordsets was painfully slow. My code runs well and I
> accomplish my objective to compare what amounts to one table of over
> 4000 records and a second table of over 2800 records in 37 seconds. I
> am happy with the outcome and the results are written to an Access
> database with 3 tables showing the differences both ways and where the
> data is equal. I am providing the below code as a reference to my
> question.
>
> Is there a more efficient way of comparing this data so that I can see
> the differences each way and where the data is the same? This is just
> the start of a very large project and I will be comparing many tables
> across different databases and I am looking to make this as efficient
> as possible. Is it possible to compare the data both ways and keep it
> to a single loop or is there a more creative solution available.
>
> Thanks for any suggestions.


Are you aware of MS-Access' built-in capabilities under Queries?

Find Duplicates Query Wizard
Find Unmatched Query Wizard



Re: Compare 2 tables for matches and differences by Bob

Bob
Sat Mar 18 12:18:48 CST 2006

clu wrote:
> I am trying to compare 2 tables from 2 different databases using ODBC.

What database are you using?
As the other responses indicate, it is probably possible to construct a
query that does what you want instead of this horrid looping code.
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"



Re: Compare 2 tables for matches and differences by clu

clu
Mon Mar 20 08:25:39 CST 2006

Thank you for your suggestions,

I am comparing a table from an oracle/unix database and a DB2/AS400
database and am only concerned with 1 field which has the same data
type. I save the data to an Access database to view the results. This
code will be used to compare similiar data to other tables of the same
database types. I am trying to keep the code dynamic so that I can
compare oracle/unix to oracle/unix or DB2/AS400 to DB2/AS400 or
DB2/AS400 to oracle/unix. I will probably end up comparing the results
from Access to the other databases at some point as well. I am working
in Windows XP.


Re: Compare 2 tables for matches and differences by Alexander

Alexander
Mon Mar 20 08:55:29 CST 2006

Hi clu!

clu schrieb:

> Thank you for your suggestions,
>
> I am comparing a table from an oracle/unix database and a DB2/AS400
> database and am only concerned with 1 field which has the same data
> type. I save the data to an Access database to view the results. This
> code will be used to compare similiar data to other tables of the same
> database types. I am trying to keep the code dynamic so that I can
> compare oracle/unix to oracle/unix or DB2/AS400 to DB2/AS400 or
> DB2/AS400 to oracle/unix. I will probably end up comparing the results
> from Access to the other databases at some point as well. I am working
> in Windows XP.

In this case I'd export both original tables into the access database
and then run the compare locally against the access-tables and also
store the results to access. Finally do the updates on the original
dbs, if updates are required.

Mfg,
Alex