1

Many are aware that the IIF function does not "short circuit". Does the iif function compute both paths in SSRS or is it short-circuited?

So, does the Switch function also not short circuit? In other words suppose we have this Switch:

Switch(True, 5, False, 5/0) a contrived example of course.

Will it cause an error because it will evaluate 5/0?

Community
  • 1
  • 1
Don Cheadle
  • 5,224
  • 5
  • 39
  • 54
  • 1
    I hate to be the one to ask this, but.... **have you tried it?** – Cᴏʀʏ Feb 05 '16 at 22:02
  • @Cᴏʀʏ - I did, admittedly with a more complex `Switch`. And to my amazement it looked like it *did* evaluate all the results - like the `IIF` does. But I haven't tested such a straight forward example as this. When I have time I will, and probably post an answer if no one else has. – Don Cheadle Feb 05 '16 at 22:07

1 Answers1

2

Switch doesn't short circuit. It shows the same behavior as iif evaluates all conditions.

But the expression Switch(True, 5, False, 5/0) won't show an #error.

It will evaluate fine. It will show 5. As 5/0 will evaluate in SSRS as infinity not #error.

A better test will be

=SWITCH(TRUE,5,FALSE,5/"")

When using the above expression, SSRS will evaluate it to #error instead of 5.

Anup Agrawal
  • 6,551
  • 1
  • 26
  • 32
  • 1
    i find myself returning to read this question/answer because I just can't accept that SSRS has all this hasltle – Don Cheadle Feb 17 '16 at 14:24