Why isn't my iif statement evaluating true when the condition is correct?

北战南征 提交于 2019-12-13 06:42:12

问题


This is my statement:

iif(sum(Fields!myfield1.Value) = 0, 0, sum(Fields!myField2.Value)/sum(Fields!myField1.Value))

Any suggestions?


回答1:


Likely it is evaluating as True. As mentioned in other comments, you'll get an error anyway because Iif() evaluates all parameter expressions regardless of the result of the test.

The error can be avoided by adding another Iif() in the divisor.

iif(
    sum(Fields!myfield1.Value) = 0,
    0,
    sum(Fields!myField2.Value) / iif(
                                     sum(Fields!myfield1.Value) = 0,
                                     1,
                                     sum(Fields!myField1.Value)
                                 )
)

Now you'll get zero if myfield1 is zero and no error is thrown.

(You probably should show 'N/A' or just an empty string when the divisor is zero, though.)



来源:https://stackoverflow.com/questions/2822233/why-isnt-my-iif-statement-evaluating-true-when-the-condition-is-correct

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!