Ranjan Marathe Blog

TIL: Handling Division by Zero with NULLIF in SQL Server

The Problem

Dividing by zero in SQL Server raises an error, potentially breaking queries.

Solution: NULLIF

NULLIF(expression1, expression2) returns:

Example:
```sql SELECT 100 / NULLIF(0, 0) – Returns NULL (no error)