简体   繁体   English

具有计算表达式的子查询的条件表达式中的数据类型不匹配

[英]Data type mismatch in criteria expression for the subquery with calculated expression

I am trying to create a SQL subquery in MS Access. 我正在尝试在MS Access中创建一个SQL子查询。 Getting "type mismatch in expression 在表达式中获取“类型不匹配”
criteria" error message. 条件”错误消息。

Subquery is 子查询为

SELECT *
  (SELECT Locs_Eq.Locs_Eq 
   FROM Locs_Eq 
   WHERE Query6.StDeExtrREF=CStr(Locs_Eq.Full_VendSN)
  ) AS Loc_1
FROM Query6

The variable DeExtrREF from Query6 is as follows: 可变DeExtrREFQuery6如下:

 IIF(PDetail.VeName="Siem" AND [DeExtr1]="Contr REF#",
     TRIM(MID (PDetail.Desc, (InStr([PDetail.Desc],":")+1), LEN(PDetail.Desc))),
     TRIM(MID (PDetail.Desc, (InStr([PDetail.Desc],":")+1), LEN(PDetail.Desc))) 
    ) AS DeExtrREF

I tried adding CStr to the variables, still receive the error message. 我尝试将CS​​tr添加到变量中,但仍然收到错误消息。 Please help. 请帮忙。

I will assume that you have a comma after SELECT * on the first line. 我假设您在第一行的SELECT *之后有一个逗号。 If not, change this first and see if this helps. 如果不是,请先更改此设置,看看是否有帮助。

I am not certain, but it is probably a null-related error; 我不确定,但这可能是与null相关的错误; Add this to a module in your access app: 将此添加到您的访问应用程序中的模块:

public function is_null(val as variant, rplc as string) as string
    if isnull(val) then
        is_null = rplc
    else
        is_null = cstr(val)
    end if
end function

then change your query to use this, as follows: 然后更改您的查询以使用它,如下所示:

SELECT q.*,
  (SELECT l.Locs_Eq 
   FROM Locs_Eq l 
   WHERE is_null(q.StDeExtrREF, "") = CStr(is_null(l.Full_VendSN, ""))
  ) AS Loc_1
FROM Query6 q

Hope this helps. 希望这可以帮助。 I alias tables and queries automatically, but as a general rule you're more likely to get help here if your queries are not too difficult to understand. 我会自动为表和查询加上别名,但是通常来说,如果您的查询不太难理解,您很可能会在这里获得帮助。

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

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