I am trying to compare two tables from different databases.
with what aim? what result do you want? return records in db x that don't match in db y (which is what you are trying to do)? the other way round? both? what are you going to do with the information once you have it?
your code as presented will fail due to typo's. Which implies you have free typed it rather than use copy/paste. Aside from the fact that free typing takes longer, it gives me no confidence we are even looking at the real problem
there are several things that need to be taken into consideration which would be to cumbersome to discuss here.
if we knew those considerations, we might be able to suggest a better way.
but that aside could perhaps make it simpler although it would still negate the use of indexes
Code:
SELECT x.*
FROM ( SELECT *, ID & ';' & fldId & ';' & fldInstrNr & ';' & fldCode & ';' & fldQty & ';' & fldUnit & ';' & fldType & ';' & zsfldDemo as compare
FROM tblA 'C:\F1\db.mdb'
) x
LEFT JOIN
( SELECT * , ID & ';' & fldId & ';' & fldInstrNr & ';' & fldCode & ';' & fldQty & ';' & fldUnit & ';' & fldType & ';' & as compare
FROM tblA IN 'C:\F2\db.mdb'
) y
ON (x.compare = y.compare)
If this is a regular occurrence I would use a hash function on all the relevant fields and compare on that - probably only going to compare 8 or 10 chars rather the larger number you have at the moment. Perhaps even store the hash value in an additional indexed field.
Another way to try using a non standard join (so can only be done in the sql window)
Code:
SELECT x.*
FROM ( SELECT *
FROM tblA 'C:\F1\db.mdb'
) x
LEFT JOIN
( SELECT *
FROM tblA IN 'C:\F2\db.mdb'
) y
ON (x.id<>y.id)
AND (x.fldId = y.fldId)
AND (x.fldInstrNr = y.fldInstrNr)
AND (x.fldCode = y.fldCode)
AND (x.fldQty = y.fldQty)
AND (x.fldUnit = y.fldUnit)
AND (x.fldType = y.fldType) #
AND (x.zsfldDemo<>y.zsfldDemo)
other comment: your nz function should be a bit faster if you provide a default value should you choose to try that way again
(Nz(x.fldId,0) = Nz(y.fldId,0))
use 0 for numbers and '' for strings