Do you have a comment or suggestion to improve SQL Server? We’d love to hear it!

DIVIDE function in T-SQL

The languages MDX and DAX both have a DIVIDE function, which has the following syntax:

DIVIDE(<numerator>, <denominator> [,<alternateresult>])
The alternate result is specified as the result when a division by zero is encountered. If it isn't specified, NULL is returned.

This would be a fine addition to the T-SQL language.

35 votes
Sign in
(thinking…)
Sign in with: oidc
Signed in as (Sign out)

We’ll send you updates on this idea

Koen Verbeeck shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

1 comment

Sign in
(thinking…)
Sign in with: oidc
Signed in as (Sign out)
Submitting...
  • Alan Singfield commented  ·   ·  Flag as inappropriate

    To just avoid divide by zero:

    result = numerator / NULLIF(denominator, 0)

    Or to put an alternate result:
    result = ISNULL(numerator / NULLIF(denominator, 0), 12345)

Feedback and Knowledge Base