简体   繁体   English

Excel ODBC SQL语句引发错误'[ODBC EXCEL驱动程序]数据类型不匹配

[英]Excel ODBC SQL Statement Throwing Error '[ODBC EXCEL Driver] Data Type Mismatch in criteria

The SQL statement below inserts values into a new table, in a new sheet (TempPoints). 下面的SQL语句将值插入到新表的新表(TempPoints)中。 If I remove the last part of the statement (in bold) the query runs OK however when I add it back in to the statement I receive the following error message; 如果删除语句的最后部分(粗体),则查询运行正常,但是将其重新添加到语句中时,会收到以下错误消息; '[ODBC EXCEL Driver] Data Type Mismatch in criteria'. “ [ODBC EXCEL驱动程序]条件中的数据类型不匹配”。

I have replicated the tables and query in SQLServer and it runs OK and as expected which proves the full statement is OK. 我已经在SQLServer中复制了表和查询,并且它运行正常,并且按预期证明了完整的语句正常。 Is this a limitation of the Excel ODBC driver?? 这是Excel ODBC驱动程序的限制吗?

Thank you in advance. 先感谢您。

strSQL = "INSERT INTO [TempPoints$] (REFP, PointItemRef, LoadItemRef, PointDES, Iotype, Subtype, Notes) " & _
               "SELECT " & tempref & ", [PointsDB$].ItemRef, [LoadstoPointsDB$].LoadRef, [PointsDB$].PointDES, [PointsDB$].Iotype, [PointsDB$].Subtype, [PointsDB$].Notes " & _
               "FROM [LoadsToPointsDB$] INNER JOIN [PointsDB$] ON [LoadsToPointsDB$].PointRef = [PointsDB$].ItemRef " & _
               "WHERE [LoadsToPointsDB$].LoadRef = " & moditemref & " AND [PointsDB$].SystemComp = 'Y' " & _
               **"AND NOT EXISTS (SELECT * FROM [TempPoints$] WHERE [TempPoints$].PointItemRef = [PointsDB$].ItemRef)"**

Thank you for those that viewed this, but I seem to have found the answer. 感谢您查看此内容的人,但我似乎找到了答案。

There is a previous insert into statement that loads data in the table, once the data was being loaded into it, the table was storing the numbers as text and not integers. 之前有一个insert语句,用于将数据加载到表中,一旦将数据加载到表中,该表会将数字存储为文本而不是整数。 After removing the rows and ensuring the format of the columns was set to integer the SQL query began to function as expected. 删除行并确保列的格式设置为整数后,SQL查询开始按预期运行。

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

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