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 2008 Forums
 Transact-SQL (2008)
 Divide By Zero Error

Author  Topic 

evanburen
Posting Yak Master

167 Posts

Posted - 2013-11-26 : 16:10:52
I'm trying different techniques of avoiding an error of "divide by zero error encountered". I'm trying to use NULLIF in the denominator but can't get it to work. Thanks

SELECT 	
ROUND((COUNT(CASE WHEN Score_CorrectID = 0 Then Score_CorrectID END) / CAST(COUNT(PCAID) AS Float) *100),0) As Score_CorrectID_Errors_Percent
FROM Calls
WHERE PCAID = 2

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2013-11-26 : 16:23:34
[code]
SELECT
ROUND((COUNT(CASE WHEN Score_CorrectID = 0 Then Score_CorrectID END) / nullif(CAST(COUNT(PCAID) AS Float),0) *100),0) As Score_CorrectID_Errors_Percent
FROM Calls
WHERE PCAID = 2
[/code]

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -