简体   繁体   English

SELECT语句-查询表达式''中的语法错误

[英]SELECT Statement - Syntax error in query expression ' '

Trying to SELECT a row in my excel file. 尝试在我的Excel文件中SELECT一行。 I'm using it as a database. 我正在将其用作数据库。 I'm pretty sure the problem is either in my query or in my excel file. 我很确定问题是在查询中还是在Excel文件中。

SELECT * FROM [tableName$] where _columnNum1 = 'testData123'"

I've tried doing this code for a while 我已经尝试过这段代码了一段时间

SELECT * FROM [tableName$]

and it worked. 而且有效。 So every time I add a WHERE clause, it causes the error. 因此,每次我添加WHERE子句时,都会导致错误。 What seems to be the problem here? 这里似乎是什么问题?

The error says Syntax error in query expression '_columnNum1 = 'testData123'' 该错误表明Syntax error in query expression '_columnNum1 = 'testData123''

UPDATE: I forgot to add this, I've already googled this thing for some time now, and the error is about data types. 更新:我忘记添加它了,我已经用谷歌搜索了一段时间,并且错误是关于数据类型的。 But since I'm using excel as a database, I can't really manipulate data types around them. 但是由于我将excel用作数据库,所以我无法真正操纵它们周围的数据类型。 Or can I? 可以吗 Anyway maybe the error is about data types. 无论如何,错误可能与数据类型有关。

After hours of searching, finally got the answer. 经过数小时的搜索,终于找到了答案。 I simply added brackets on the column name. 我只是在列名称上添加了括号。 I didn't need them when I was inserting data in my excel file. 当我在excel文件中插入数据时,我不需要它们。

I have the string sql of 我有字符串sql

SELECT * FROM [tableName$] where _columnNum1 = 'testData123'"

when it should be 什么时候应该

SELECT * FROM [tableName$] where [_columnNum1] = 'testData123'"

I got the answer here: 我在这里得到答案:

SOURCE: OLE CALL to Excel with WHERE clause 源: OLE CALL到带有WHERE子句的Excel

Another note, for people who has trouble inserting data in their excel where the data does not go to the first row, the source might be the answer, too. 另一个要注意的是,对于那些无法在excel中插入数据而无法将数据转到第一行的人来说,来源也可能是答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM