Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8145615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:43:05+00:00 2026-06-06T13:43:05+00:00

I am having problems with dividing by zero. If the denominator is zero I

  • 0

I am having problems with dividing by zero. If the denominator is zero I would like the value to be zero. When I try using nullif, I end up with a zero or one for the calculated value.

Here is the SQL:

Select 
    StateCode, Month1Date,(Sum(Order)/Sum(Value)) as myValue    
from tblOrders    
     inner join tblStates on OrderStateCode = StateCode    
group by StateCode, Month1Date
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T13:43:07+00:00Added an answer on June 6, 2026 at 1:43 pm
    Select
      StateCode,
      Month1Date,
      ISNULL(Sum(Order) / NULLIF(Sum(Value), 0), 0) AS myValue
    from
      tblOrders
    inner join
      tblStates
        on OrderStateCode = StateCode
    group by
      StateCode,
      Month1Date
    

    A 0 denominator is changed to NULL, which will cause the result to be NULL. The whole result then has ISNULL() to turn any NULLs to 0’s.

    Personally I would not include the ISNULL() and leave the result as NULL. But it depends on use-case really.

    EDIT: Deleted the CASE WHEN version as another answer had it just before mine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having problems getting JBoss to inject an environment variable value into a
I have started having problems with my VPS in the way that it would
I'm having problems compiling the following program. I'm using gcc -framework Foundation inherit8.1m and
I having trouble in dividing the HTML frames. I have been using the following
Having problems with my ASP.NET MVC2 project. I'm using Fluent NHibernate as ORM, and
Having problems with this setup what im trying to do is like so. Steps
I'm having problems running my Rails unit tests via autotest using Test::Unit 2.0.6. Running
Having problems; using both queries in the same controller for the same view. First
I`m having problems for do something like this: http://imageshack.us/photo/my-images/824/examplehm.png/ My xml code shows 3
I'm having problems with jetty crashing intermittently, I'm using Jetty 6.1.24. I'm running a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.