简体   繁体   English

访问查询中的“ IIf with In”运算符

[英]“IIf with In” operator in access Query

Hello Thanks in advance, 您好,谢谢,

Need a quick help in access query with IIF and IN operator together. 一起使用IIF和IN运算符进行访问查询时需要快速帮助。

Trying to achieve below mentioned criteria in a query but but not working for this case " In ("Ordered", "Pending") " however if I put a single value without IN operator then it works. 尝试在查询中实现以下提到的条件,但在这种情况下不起作用“ In(“ Ordered”,“ Pending”)“,但是,如果我将单个值不带IN运算符,那么它将起作用。

Like IIf([Forms]![ReportCriteriaSelection]![StatusForSup]=0,IIf(IsNull([Forms]![ReportCriteriaSelection]![RepCritOdrStatus]),"*",[Forms]![ReportCriteriaSelection]![RepCritOdrStatus]),In ("Ordered", "Pending"))

I will assume in this answer that the subject of this condition is FieldX . 我将在此答案中假定此条件的主题是FieldX Just replace it with whatever you have on the left of the Like operator. 只需将其替换为Like运算符左侧的内容即可。

The problem 问题

You cannot combine Like and In operators like that. 您不能这样结合使用LikeIn运算符。 If you resolve all the IIf conditions, the erroneous expression really comes down to this: 如果您解决了所有IIf条件,那么错误的表达实际上可以归结为:

FieldX Like In ("Ordered", "Pending")

...which is invalid syntax. ...这是无效的语法。 Valid would be either: 有效值为:

FieldX Like "Ordered"

or: 要么:

FieldX In ("Ordered", "Pending")

The Solution 解决方案

As you want to use different operators on this FieldX depending on other conditions, you need to express this using multiple WHERE conditions: 由于要根据其他条件在此FieldX上使用不同的运算符,因此需要使用多个WHERE条件来表达此条件:

WHERE  (    [Forms]![ReportCriteriaSelection]![StatusForSup] = 0 
       AND  FieldX = Nz([Forms]![ReportCriteriaSelection]![RepCritOdrStatus], FieldX)
       )
  OR   (    Nz([Forms]![ReportCriteriaSelection]![StatusForSup],1) <> 0 
       AND  FieldX IN ("Ordered", "Pending")
       )

The above should be equivalent with what you intended to do. 上面的内容应该与您打算做的等同。 I made use of the Nz function . 我利用了Nz函数

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

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