How to SELECT column which field name contains a dot

我怕爱的太早我们不能终老 提交于 2020-11-29 09:26:08

问题


I am using ADO to import data from Excel workbooks. I'm having some troubles with one worksheets where one column name contains a dot : "Col.1".

I tried everything I found : double quotes, brackets, backstick. Nothing works. Either an error is raised or the query output "Col.1" on every row.

QUERY_SQL = _
"SELECT `Col.1`, Col3 FROM [table$] " & _
"IN '" & SourcePath & "' " & CHAINE_HDR

Given the fact that I can't rename the column in the source file,

How can I manually select this column using its name not its number ([F1]) ?


回答1:


I finally found how to retrieve data from this column.

You need to replace "." by "#" and put the column name in square brackets or backsticks :

QUERY_SQL = _
"SELECT `Col#1`, Col3 FROM [table$] " & _
"IN '" & SourcePath & "' " & CHAINE_HDR

However this will not work in INSERT INTO queries. :

INSERT INTO [sheet$] (Col2, `Col#4`) IN '" & TargetPath & "' 'Excel 12.0;' " & QUERY_SQL

While this is less problematic for me as I can rename all field in the target sheets, this is still a strange behaviour.



来源:https://stackoverflow.com/questions/43784289/how-to-select-column-which-field-name-contains-a-dot

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