Use the NULLIF(value, 0)
function, where value
is a potential divisor. If it equals zero, NULL
will be returned; otherwise, the correct division result will be returned.
Example:
SELECT 30 / NULLIF(0, 0)
\[NULL\]
SELECT 30 / NULLIF(5, 0)
6