divide by zero/null workaround in SSRS 2008 report

前端 未结 4 1900
失恋的感觉
失恋的感觉 2020-12-01 17:01

I have a report with a field whose value was the expression:

Fields!TotalPrice.Value/Fields!TotalSlots.Value

Although sometimes TotalSlots

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-01 17:32

    This only seems to happens when the division is one of the results of an IIF, not if you just write a formula to divide one by the other, e.g.

    =IIF(thing=1,10/0,0)
    

    Before it has evaluated thing, it has already tried to calculate both results, causing an error. You can't use IIF in this way to protect from zero, you have to put the IIF on the bottom line of the division, e.g.

    =IIF(thing=1, 10/IIF(divisor=0,-99999999999,divisor),0)
    

    This is not satisfactory, since we've introcudes a weird small non zero number as the result, but it may be ok if you just want a non-error.

    Technically, the #error is the correct answer.

提交回复
热议问题