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:
NULLifexpression1equalsexpression2expression1if they differ
Example:
```sql
SELECT 100 / NULLIF(0, 0) – Returns NULL (no error)