如何在表达中使用Iif Stament [英] How to use an Iif Stament in an Expresion

查看:116
本文介绍了如何在表达中使用Iif Stament的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我在c#

中有这行代码我一直收到此错误=>

语法错误:'&'运算符之前缺少操作数。

以下是我的代码感谢任何建议



Hi guys I have this line of code in c#
I keep getting this error=>
Syntax error: Missing operand before '&' operator.
Find below is my code thanks for any advice

< ds.Tables[0].Columns.Add("RESULTS").Expression = "Iif(((ActualWeight >= (.96 * TargetWeight)) And (ActualWeight <= (1.04 * TargetWeight))),'GOOD',And (ActualWeight < (0.96 * TargetWeight))),'BAD', And (ActualWeight > (1.04 * TargetWeight))) 'BAD',null)";/pre>

推荐答案

我想你数据集公式使用VBA,因此您应该使用AND而不是&&。



尝试



Iif((ActualWeight> =(。96 * TargetWeight))和(ActualWeight < =(1.04 * TargetWeight)),'GOOD','BAD')
I think the dataset formula uses VBA so you should be using AND rather than &&.

Try

Iif((ActualWeight >= (.96 * TargetWeight)) And (ActualWeight <= (1.04 * TargetWeight)),'GOOD','BAD')


看起来你想要嵌套的 Iif 语句。尝试:

Looks like you want nested Iif statements. Try:
Iif(((ActualWeight >= (.96 * TargetWeight)) And (ActualWeight <= (1.04 * TargetWeight))), 'GOOD', Iif(ActualWeight < (0.96 * TargetWeight), 'BAD', Iif(ActualWeight > (1.04 * TargetWeight), 'BAD', null)))





将表达式放在多行上可能会使事情变得更清晰:



Putting the expression on multiple lines might make things clearer:

Iif(
    ((ActualWeight >= (.96 * TargetWeight)) And (ActualWeight <= (1.04 * TargetWeight))), 
    'GOOD', 
    Iif(
        ActualWeight < (0.96 * TargetWeight), 
        'BAD', 
        Iif(
            ActualWeight > (1.04 * TargetWeight), 
            'BAD', 
            null
        )
    )
)



编辑:正如Maciej Los指出的,你可以简化公式,这样你就不需要嵌套 Iif 秒。有关详细信息,请参阅解决方案#3。


As Maciej Los pointed out, you can simplify the formula so that you don't need nested Iifs. See solution #3 for details.


请参阅我对该问题的评论。

我想你必须定义公式:

Please, see my comment to the question.
I guess you have to define formula ths way:
="Iif((ActualWeight > .96 * TargetWeight) And (ActualWeight <= 1.04 * TargetWeight),'Good','Bad');





没有必要定义嵌套的iif's。如果ActualWeight为Bigger Then ...而LessOrEqual则为...... - 则条件为真,否则为false。



There is no need to define nested iif's. If ActualWeight is Bigger Then ... and LessOrEqual then ... - then condition is true, else false.


这篇关于如何在表达中使用Iif Stament的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆