Please note that iif() is a function and therefore all parameters will be evaluated before calling the function. One solution has been posted by Scott. A working solution for A/B using only iif is:
=iif(B=0, 0, A / iif(B=0, 1, B))
hth,
Gerald
see also this thread:
attempt to divide by zero
My case was similar to this and I had to do something slightly more.
I'm using SSRS 2005 at this momen, if and in the above scenario quoted by Gerald, I'm passing a DECIMAL(18,2) for both my "A" and "B" values. Because of that, I did the following to make my report not throw and #ERROR, but instead, a zero.
=iif(B = 0, 0, iif(A = 0, 0, A) / iif(B = 0, 0, B))
For some reason, SSRS (2005 anyway) does not like a divide by zero with any decimals anywhere in the equation, it seems, which is why (I guess) I'm technically changing the "A" decimal to an int???
Don't know, but glad it works. ;-)