Divide by Zero Error

Divide by Zero Error

This knowledge base article will assist you with how to resolve the Divide by Zero error. This is a common error that occurs in Crystal Reports. Going through this article, you will learn about the error in overview, the reason for the error, and the solution to resolve the problem.


Overview:

The Divide by Zero error may arise in Crystal Reports, iVend Report Designer reports and SQL Query Reports.


This article has highlighted a few important possible reasons that cause this error to be returned. Read the complete article to understand the reasons and how to resolve them.


Reason:

This error occurs if the divider value results in “0”when applying any division formula.


Solution:

The following lists the solutions to the Divide by Zero error with respect to their different reporting scenarios:


  • When the error occurs in a Crystal Reports report:

    IF {@Qty}=0 THEN 0 ELSE Sum(TotalAmount)/{@Qty}

  • When the error occurs in an iVend Retail Report Designer Report:

    {SaleTransaction.Qty==0? ”0.00”: Sum(SaleTransaction .TotalAmount)/ SaleTransaction.Qty}

  • When the error occurs in a SQL Query Report: Select Item, Sum(Qty) As Qty, Sum(TotalAmount) AS TotalAmount, Sum(TotalAmount)/NULLIF(Sum(Qty),0) AS AvaragePrice From Product Group BY Item