Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Divide By Zero Error 1

Status
Not open for further replies.
Dec 11, 2009
60
US
I have the below Case statement that is giving me a "Divide by zero error"

CASE WHEN sum(p2.TempsonStreet) > 0 THEN MIN(ISNULL(p2.AvgBillRate,0) / p2.TempsonStreet) ELSE 0.00 END

However I can correct the error by doing this:

CASE WHEN sum(p2.TempsonStreet) > 0 THEN MIN(ISNULL(p2.AvgBillRate,0)) / sum(p2.TempsonStreet) ELSE 0.00 END

It doesn't give me the correct results?
 
try...

Code:
CASE WHEN sum(p2.TempsonStreet) > 0 THEN MIN(ISNULL(p2.AvgBillRate,0) / [!]NullIf([/!]p2.TempsonStreet[!], 0)[/!]) ELSE 0.00 END

The problem is, TempsonStreet contains 0. NullIf will cause NULL to be used instead of 0.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Thanks a million!! I have been struggling with this for a while.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top