Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi,

I have a sql query and i keep on getting this error :

Msg 8134, Level 16, State 1, Line 1
Divide by zero error encountered.

SQL
select ((sum(vews.TransactionCount) * 100) / (fa.new_unitspurchased)) as percentage from
BingMapsPlatform_Staging.dbo.VEWSDailyAggTrans vews
inner join BingMapsPlatform_MSCRM.dbo.FilteredAccount fa
on new_accountid = vews.primaryId
group by fa.new_unitspurchased


Please help me with this.
Posted
Comments
Pawan Sharma Software Engineer 11-Dec-12 0:58am    
select IsNull(Case when IsNull(fa.new_unitspurchased,0)> 0 then ((sum(vews.TransactionCount) * 100) / (fa.new_unitspurchased)) Else 0 End ,0) as percentage from
BingMapsPlatform_Staging.dbo.VEWSDailyAggTrans vews
inner join BingMapsPlatform_MSCRM.dbo.FilteredAccount fa
on new_accountid = vews.primaryId
group by fa.new_unitspurchased

select isnull(((sum(vews.TransactionCount) * 100) / isnull(fa.new_unitspurchased,0)),0) as percentage
from
BingMapsPlatform_Staging.dbo.VEWSDailyAggTrans vews
inner join BingMapsPlatform_MSCRM.dbo.FilteredAccount fa
on new_accountid = vews.primaryId
group by fa.new_unitspurchased
 
Share this answer
 
select IsNull(Case when IsNull(fa.new_unitspurchased,0)> 0 then ((sum(vews.TransactionCount) * 100) / (fa.new_unitspurchased)) Else 0 End ,0) as percentage from BingMapsPlatform_Staging.dbo.VEWSDailyAggTrans vews inner join BingMapsPlatform_MSCRM.dbo.FilteredAccount fa on new_accountid = vews.primaryId group by fa.new_unitspurchased
 
Share this answer
 
Comments
PRASHANT KUMAR LAL 11-Dec-12 2:42am    
I also wanted to have the percenatge symbol(%) in the end result. How to do that?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900