MSSQLMSSQL 8134

MSSQL 8134: Divide by Zero Error Encountered

SQL Server error 8134 is raised when an arithmetic expression divides by zero. The statement is aborted unless error handling is in place.

Example Query

SELECT revenue / units_sold FROM sales;
-- Fails when units_sold = 0

Common Causes

  1. 1Dividing by a column that can contain zero
  2. 2Computed denominator that evaluates to zero
  3. 3Aggregation (SUM, COUNT) used as divisor without filtering empty groups

How to Fix It

Use NULLIF to prevent division by zero: revenue / NULLIF(units_sold, 0). Wrap with ISNULL or COALESCE for a default: ISNULL(revenue / NULLIF(units_sold, 0), 0). Enable SET ARITHABORT ON to fail fast during development.

Need a reliable database?

Try Supabase — free PostgreSQL with a generous free tier. No credit card required.

Get started free →

Got a query causing this error?

Paste it into SQLbuddy and get an instant plain-English explanation with optimization tips.

Analyze My Query →