Cannot select range for sheet names with special characters (OLE DB SQL Server)

ykejflvf  于 2023-08-02  发布在  SQL Server
关注(0)|答案(1)|浏览(129)

I'm trying to select data from Excel using OLE DB, but the other sheet names in the provided file has special characters.

For example: Sample_Sheet - #1

How do I go about this?

I tried

SELECT * 
FROM [Sample_Sheet - #1$]

and it displays the data.

However, when I specify a range in the query:

SELECT * 
FROM [Sample_Sheet - #1$D7:G22]

OLE DB throws an error

Microsoft Access database engine could not find the object

Any insights will be appreciated. Thank you!

bhmjp9jg

bhmjp9jg1#

Your SELECT statement looks very dubious.

Here is how it is usually done in SSMS:

SELECT *
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
   'Excel 12.0 Xml;
    Database=e:\Temp\SheetWithTable.xlsx',
    'SELECT * FROM [SheetWithTable$A1:B3]');

相关问题