SSRS 2008 - Dealing with division by zero scenarios

后端 未结 4 1795
北海茫月
北海茫月 2020-11-30 07:16

We\'re running into a problem with one of our reports. In one of our tablixes a textbox has the following expression:

=Iif(Fields!SomeField.Value = 0, 0, Fie         


        
4条回答
  •  -上瘾入骨i
    2020-11-30 07:46

    IIf will always evaluate both results before deciding which one to actually return.

    Try

    =IIf(Fields!SomeField.Value = 0, 0, Fields!SomeOtherField.Value / IIf(Fields!SomeField.Value = 0, 1, Fields!SomeField.Value))
    

    This will use 1 as the divisor if SomeOtherField.Value = 0, which does not generate an error. The parent IIf will return the correct 0 for the overall expression.

提交回复
热议问题