Martin Dreher Martin Dreher - 11 months ago 84
SQL Question

query excel with sql

Using MS Office+VBA (or, sometimes, Visual Studio 2010) I am looking for a way to query Excel-Files using only SQL Query, similar to this way of querying a textfile:

SELECT * FROM [Text;DATABASE=L:\Testfiles].test1.csv

As a result I would expect something like:

SELECT * FROM [Excel File=L:\Testfiles\test2.xls].[sheet1$A1:B1000]

I am not looking for a way to query Excel-Files with SQL and a ADODB-connection string (as depicted on or here on, since I want all information regarding the data source inside the actual SQL-Code, and not split up between SQL and the connection setup in VB/VBA.

Any hints would be greatly appreciated.


Answer Source

You can use FROM clause like this:

FROM [sheet1$A3:E22] IN 'C:\path\MyFile.xlsx' [Excel 12.0;HDR=YES;IMEX=0]