divide by zero/null workaround in SSRS 2008 report

前端 未结 4 1894
失恋的感觉
失恋的感觉 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:35

    The VB IIF evaluates all arguments, so it will throw an error if any argument throws an error:

    Your formula can be written as:

    =IIF(Fields!TotalSlots.Value > 0,
       Fields!TotalPrice.Value /
       IIF(Fields!TotalSlots.Value > 0,
           Fields!TotalSlots.Value,
           1 ),
       "unknown")
    

    Then even when TotalSlots is zero, the formula still won't encounter a division problem.

提交回复
热议问题