How to SELECT [header text w. dot] AS xxx FROM an

2019-09-16 17:48发布

Summary: Using the Jet.OLEDB provider and the SQL query, I do not know how to access the column the header text of which contains a dot. Is there any way to escape the dot in the SELECT query?

Details: I am using a connection string

Provider=Microsoft.Jet.OLEDB.4.0;Data source=test.xls;Extended Properties="Excel 8.0;HDR=Yes;"

When the header text of the column of an Excel sheet contains a dot (notice the dot column named Abbrev. Packing)...

Column header with dot in the text.

... then the SELECT query like this...

SELECT
  [Date] AS d,
  [Code] AS code, 
  [Abbrev. Packing] AS packing,
  [Price] AS price
FROM [Sheet1$]

... fails with error 80004005. When I remove the dot from the header text and from the SELECT command, everything works smoothly, and the data is extracted. However, the Excel table comes from third party, and I cannot change the text of the header.

How can I escape the dot in the SELECT command, or what is the way to fix it?

1条回答
老娘就宠你
2楼-- · 2019-09-16 18:32

It appears that SSIS replaces period (.) with number sign (#) when I tried to load similar spreadsheet as you provided through a SSIS package. So, I am guessing you would need to either load it through SSIS if you have that option available, otherwise you could probably try querying it directly like this:

SELECT
  [Date] AS d,
  [Code] AS code, 
  [Abbrev# Packing] AS packing,
  [Price] AS price
FROM [Sheet1$]

SSIS Sample

查看更多
登录 后发表回答