Home » excel » VBA ADO Excel Driver SQL Except/Minus operator

VBA ADO Excel Driver SQL Except/Minus operator

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have 2 tables (new data and old data) and want to query all new rows that are not present in the old data.

SELECT * FROM new 
EXCEPT 
SELECT * FROM prev

I wanted to do this with the ‘EXCEPT/MINUS’ operator in VBA ADO(using Excel sheets as tables), however it seems that EXCEPT is not an accepted operator?

I get a run-time error

[Microsoft][ODBC Excel Driver] Syntax error in FROM clause.

Is it just a feature that is not available in the ADO ODBC Excel Driver?
Other queries work just fine.

Thanks in advance!

How to&Answers:

You need to do a LEFT JOIN between the two tables and then select only those rows in NewTable that have no corresponding entries in OldTable. To do this you will need to work out which fields correspond to each other in the two tables.

SELECT * FROM NewTable 
LEFT JOIN OldTable ON NewTable.Field1 = OldTable.Field1
WHERE OldTable.Field1 IS NULL