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.
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 statementSELECT 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.salesTimestampFROM 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 |
|
|
|
|