I have a SQL query which used to cause a
Divide By Zero exception
I\'ve wrapped it in a CASE
statement to stop this fr
I'm using NULLIF
bit differently, because in some cases I do have to return some value. Usually I need to return 0 when there is a divide by zero error. In that case I wrap whole expression in ISNULL
. So it would be:
Percentage = ISNULL(100 * ClubTotal / NULLIF(AttTotal, 0), 0)
The inner part is evaluated to NULL
and then ISNULL
replaces it with 0.