dilettante
MIS
I have a Jet database with an open ADO Connection object [tt]cnCorrDB[/tt]. The database has two tables TABLE-A and TABLE-B that have identical schemas (same number of fields with same types and names).
I need to export all of the records these two tables do not have in common to a text file. "In common" is defined as a record with the same (unique) KEYFIELD value ocurring in each of the two tables.
Right now I have this, which works fine:
However I was wondering if the same thing can be done via a single query, e.g. some sort of JOIN. Am I missing the obvious here?
This isn't really a performance issue, as I said it works fine right now. I just hate to leave "poor examples" in my code if I can avoid it.
I need to export all of the records these two tables do not have in common to a text file. "In common" is defined as a record with the same (unique) KEYFIELD value ocurring in each of the two tables.
Right now I have this, which works fine:
Code:
With cnCorrDB
.Execute "SELECT * INTO [Text;Database=" & strFolder & "].[Diffs.txt] " _
& "FROM [TABLE-A] WHERE NOT EXISTS " _
& "(SELECT NULL FROM [TABLE-B] WHERE [TABLE-A].KEYFIELD = [TABLE-B].KEYFIELD)", _
lngExportedDiffsA, adCmdText Or adExecuteNoRecords
.Execute "INSERT INTO [Text;Database=" & strFolder & "].[Diffs.txt] " _
& "SELECT * FROM [TABLE-B] WHERE NOT EXISTS " _
& "(SELECT NULL FROM [TABLE-A] WHERE [TABLE-B].KEYFIELD = [TABLE-A].KEYFIELD)", _
lngExportedDiffsB, adCmdText Or adExecuteNoRecords
.Close
End With
lngExportedDiffs = lngExportedDiffsA + lngExportedDiffsB
This isn't really a performance issue, as I said it works fine right now. I just hate to leave "poor examples" in my code if I can avoid it.