Skip to content
Microsoft SQL Server

SQL Server Error 8134

Divide by zero error encountered

Applies to: All supported SQL Server versions (2016 to 2025), Azure SQL Database, Azure SQL Managed Instance
Last technically reviewed 23 October 2026 on SQL Server 2025 (17.0.1145.4)
The full message
Msg 8134, Level 16, State 1, Line 1
Divide by zero error encountered.
Error number
8134
Severity
16 (user-correctable error)
State
1
Product
Microsoft SQL Server Database Engine
Versions
All supported SQL Server versions (2016 to 2025), Azure SQL Database, Azure SQL Managed Instance
Last reviewed
23 October 2026

What it means

Error 8134 means an expression divided by zero, with / or with the modulo operator %, so SQL Server stopped the statement.

The message never says which expression or row failed, only the line of the statement. Look at every / and % in that statement and ask which divisor can be zero. A single row is enough: SQL Server evaluates the expression row by row and stops at the first zero divisor, so you may see some rows before the error.

The usual culprits are ratios and averages computed by hand (revenue / units, total / count), percentages with a zero base, and divisors that were NULL until ISNULL(x, 0) or COALESCE(x, 0) turned them into zero. Dividing by NULL does not raise 8134; it returns NULL, which is why NULLIF is the standard fix.

Common causes

  • A divisor column that is zero in at least one row, such as units, quantity or a count.
  • A variable or aggregate used as a divisor that is zero for some inputs, for example COUNT(*) of an empty group.
  • ISNULL(divisor, 0) or COALESCE(divisor, 0) converting a NULL divisor into a zero divisor.
  • The modulo operator % with a zero right-hand side.

Diagnose it

Read-only These queries only read metadata and dynamic management views. They do not change data, permissions or configuration, so they are safe to run first.

Find the rows with a zero divisor

SELECT product, revenue, units
FROM dbo.Sales
WHERE units = 0;
What to look for

Each row returned would raise 8134 in revenue / units. Decide what the result should be for these rows: NULL, 0 or excluded.

Check the session settings that control the error

SELECT SESSIONPROPERTY('ARITHABORT') AS arithabort,
       SESSIONPROPERTY('ANSI_WARNINGS') AS ansi_warnings;
What to look for

1 and 1 is the normal setting, under which divide by zero raises 8134. If the same query errors in one tool but returns NULL in another, compare these values between the two connections.

How to fix it

Each fix is labelled with what it changes. Try read-only checks and the least invasive fix first, and test changes outside production.

Guard the divisor with NULLIF

Read-only

NULLIF(units, 0) returns NULL when units is zero, and dividing by NULL gives NULL instead of an error. This is the targeted, standard fix.

SELECT product,
       revenue / NULLIF(units, 0) AS price_per_unit
FROM dbo.Sales;

Show a default instead of NULL

Read-only

Wrap the guarded expression in COALESCE when a report needs a number. Keep the NULLIF inside; COALESCE on the divisor would bring the zero back.

SELECT product,
       COALESCE(revenue / NULLIF(units, 0), 0) AS price_per_unit
FROM dbo.Sales;

Handle the zero case explicitly with CASE

Read-only

Use a CASE expression when the zero case needs its own rule, for example a label or a different calculation.

SELECT product,
       CASE WHEN units = 0 THEN NULL
            ELSE revenue / units
       END AS price_per_unit
FROM dbo.Sales;

Examples

A ratio where the divisor is zero

CREATE TABLE dbo.Sales (
    product NVARCHAR(50),
    revenue DECIMAL(10,2),
    units   INT
);

INSERT INTO dbo.Sales (product, revenue, units)
VALUES ('Widget', 100.00, 4),
       ('Gadget', 50.00, 0);   -- units is 0 for this row

SELECT product, revenue / units AS price_per_unit
FROM dbo.Sales;
Result
Msg 8134, Level 16, State 1, Line 11
Divide by zero error encountered.

Reproduced on SQL Server 2025 (17.0.1145.4), 23 October 2026.

An average with a zero count

-- total is 0 and count is 0, so the division fails
DECLARE @total INT = 0;
DECLARE @count INT = 0;

SELECT @total / @count AS average;
Result
Msg 8134, Level 16, State 1, Line 5
Divide by zero error encountered.

Reproduced on SQL Server 2025 (17.0.1145.4), 23 October 2026.

A modulo by zero

-- the % operator fails on a zero divisor too
SELECT 10 % 0 AS remainder;
Result
Msg 8134, Level 16, State 1, Line 2
Divide by zero error encountered.

Reproduced on SQL Server 2025 (17.0.1145.4), 23 October 2026.

How to prevent it

Write every division over data with NULLIF on the divisor from the start, and agree with report owners whether an undefined ratio should show as NULL or 0. Be careful with ISNULL and COALESCE on divisors: they are a common way to manufacture a zero.

Keep the default session settings (ARITHABORT and ANSI_WARNINGS ON) rather than turning them off to hide the error. For overflow in the same calculation, see error 8115; for the functions used here, see NULLIF and COALESCE.

Common questions

Can I make SQL Server return NULL instead of the error without changing the query?

With both SET ARITHABORT OFF and SET ANSI_WARNINGS OFF, SQL Server 2025 returned NULL for 10/0 instead of raising 8134; with only one of them OFF it still raised the error. Do not rely on this: indexed views, filtered indexes and indexes on computed columns require ANSI_WARNINGS ON, and it hides the error for every expression in the session. Use NULLIF.

Should I return NULL or 0 when the divisor is zero?

NULL says the ratio is undefined, which is correct for calculations. 0 is convenient for charts but can be misleading, because zero units sold is not a price of zero. Return NULL in the data and format it in the report.

Why does my query return some rows and then fail?

Rows are produced as they are computed, so rows before the first zero divisor can reach the client before the error stops the statement. Treat the whole result as failed.

Learn more on CodeWithSQL

Official documentation

Last technically reviewed 23 October 2026; examples and diagnostics run on SQL Server 2025 (17.0.1145.4). Message text checked against the engine's sys.messages catalogue.

Still stuck on a SQL Server error?

Browse the full SQL Server error library, or get hands-on help from an experienced SQL professional.