Solved

divide by zero error

Posted on 2015-02-05
2
166 Views
Last Modified: 2015-02-05
this query is returning an error: Divide by zero error encounterd how do i fix it to make the result 0


SELECT     dbo.viewDocumentCount.[Project Name], dbo.viewDocumentCount.DocumentCount / CAST(dbo.viewTotalDays.TotalDays AS Float) AS DaysOpenAvg
FROM         dbo.viewDocumentCount INNER JOIN
                      dbo.viewTotalDays ON dbo.viewDocumentCount.ID = dbo.viewTotalDays.ID
0
Comment
Question by:vbnetcoder
2 Comments
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 500 total points
ID: 40591294
SELECT     dbo.viewDocumentCount.[Project Name],
case CAST(dbo.viewTotalDays.TotalDays AS Float)
when 0 then 0
else
dbo.viewDocumentCount.DocumentCount / CAST(dbo.viewTotalDays.TotalDays AS Float)
end AS DaysOpenAvg
FROM         dbo.viewDocumentCount INNER JOIN
                      dbo.viewTotalDays ON dbo.viewDocumentCount.ID = dbo.viewTotalDays.ID
0
 

Author Closing Comment

by:vbnetcoder
ID: 40591350
ty
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SQL Query Assistance 4 31
using BEGIN END with IF statement.. 12 40
SQL 2012 and SQL 2014 always on 9 25
GRANT, REVOKE, DENY 4 20
Written by Valentino Vranken. Introduction: The first step of creating a SQL Server Reporting Services (SSRS) report involves setting up a connection to the data source and programming a dataset to retrieve data from that data source.  The data…
A recent questions about how to add SSRS named instances, couldn't find any that talks about SQL server 2008, anyway I decided to help by creating some screen shots. The installation is straightforward, you just pop the SQL server 2008 installati…
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now