Lets say you have a query, computed column etc. that has the following formula: SomeColumnA / SomeColumnB, where SomeColumnA and SomeColumnB are non-NULL numeric columns. Clearly a problem can arise if there is a record in the database with SomeColumnB equal to 0.0, as that will result in a Divide by zero error.
Thankfully there is a rather simple solution:
use NULLIF to see if SomeColumnB was 0.0. If so, have it return NULL, and the division will result in NULL. Then wrapped the whole thing in an ISNULL, so if the division resulted in NULL, the result was 0.0.
As an alternate solution use the case statement
SomeColumnB = 0 then 0.0
ELSE SomeColumnA / SomeColumnB