在 MS Access 更新语句的 WHERE 子句中使用替换函数时出现数据类型不匹配错误
Get Data Type Mismatch error when using Replace Function in WHERE clause of MS Access Update statement
我在 MS Access 2013 中执行以下更新语句时收到错误消息 "Data type mismatch in criteria expression"。
UPDATE tblTasks
SET tblTasks.IconFilePath = "C:\Images\john.smith.jpg"
WHERE (((Replace([PersonResponsible]," ",""))="Smith,John")
AND ((Len([PersonResponsible]))>0));
当我从 WHERE 子句中删除 Replace 函数调用时,语句执行时没有错误。
PersonResponsible 字段的数据类型是 Short Text(255)。我已尝试在 CStr 和 NZ 中包装 Replace 调用,但仍然出现数据类型不匹配错误。
如有任何想法,我们将不胜感激。
谢谢
如果 [PersonResponsible] 允许空值,请将您的 SQL 更改为:
UPDATE tblTasks
SET tblTasks.IconFilePath = "C:\Images\john.smith.jpg"
WHERE (((Replace(Nz([PersonResponsible],"")," ",""))="Smith,John")
AND ((Len(Nz([PersonResponsible],"")))>0));
但实际上,您可以将其简化为:
UPDATE tblTasks
SET tblTasks.IconFilePath = "C:\Images\john.smith.jpg"
WHERE (((Replace(Nz([PersonResponsible],"")," ",""))="Smith,John"));
在这种情况下,额外的 where 子句不会增加任何更多的特异性。
我在 MS Access 2013 中执行以下更新语句时收到错误消息 "Data type mismatch in criteria expression"。
UPDATE tblTasks
SET tblTasks.IconFilePath = "C:\Images\john.smith.jpg"
WHERE (((Replace([PersonResponsible]," ",""))="Smith,John")
AND ((Len([PersonResponsible]))>0));
当我从 WHERE 子句中删除 Replace 函数调用时,语句执行时没有错误。
PersonResponsible 字段的数据类型是 Short Text(255)。我已尝试在 CStr 和 NZ 中包装 Replace 调用,但仍然出现数据类型不匹配错误。
如有任何想法,我们将不胜感激。
谢谢
如果 [PersonResponsible] 允许空值,请将您的 SQL 更改为:
UPDATE tblTasks
SET tblTasks.IconFilePath = "C:\Images\john.smith.jpg"
WHERE (((Replace(Nz([PersonResponsible],"")," ",""))="Smith,John")
AND ((Len(Nz([PersonResponsible],"")))>0));
但实际上,您可以将其简化为:
UPDATE tblTasks
SET tblTasks.IconFilePath = "C:\Images\john.smith.jpg"
WHERE (((Replace(Nz([PersonResponsible],"")," ",""))="Smith,John"));
在这种情况下,额外的 where 子句不会增加任何更多的特异性。