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

风格不统一 提交于 2019-12-13 06:05:24

问题


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)...

... 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:


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$]



来源:https://stackoverflow.com/questions/31719129/how-to-select-header-text-w-dot-as-xxx-from-an-excel-table

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!