Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 help with divide by zero error

Author  Topic 

squarefish
Starting Member

28 Posts

Posted - 2009-03-13 : 06:51:46
Hi there I have a sql statement that I am calculating percentages with. The reason I am using sql to calculate the percentages is so I can sort it very easily into highest pecent first etc.

The problem is that sometimes kccprofiles is a 0 so I get a divide by zero error.

Is there any way of doing something like
if kccprofiles = 0 then write 0 else write kccprofiles /(salesNewEnquiriesWalkin + salesUsedEnquiriesWalkin)

Below is the statement

SELECT dbo.docBranchData.branchName, dbo.docSales.salesNewEnquiriesWalkin + dbo.docSales.salesUsedEnquiriesWalkin AS phoenixenquiries,
dbo.kccprofiles.kccprofiles, (dbo.kccprofiles.kccprofiles * 100.0) / (dbo.docSales.salesNewEnquiriesWalkin + dbo.docSales.salesUsedEnquiriesWalkin)
AS percentloaded, dbo.kccprofiles.kccemails, dbo.kccprofiles.kccemails * 100 / dbo.kccprofiles.kccprofiles AS percentemails,
dbo.docSales.salesTimestamp
FROM dbo.docBranchData LEFT OUTER JOIN
dbo.kccprofiles ON dbo.docBranchData.branchID = dbo.kccprofiles.dealercode LEFT OUTER JOIN
dbo.docSales ON dbo.docBranchData.branchID = dbo.docSales.salesBranchID

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-03-13 : 06:56:50
Cross post http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=121609



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -