MySQL Forums
Forum List  »  Newbie

Evading Divide by 0 errors
Posted by: Pete Rogers
Date: August 07, 2023 02:27AM

Hi,

I'm creating a sales report for my company, and one of the things I need to do is work out the growth. To do this I've added in a calculation.

(a.[YTD Net sales]-[Previous YTD Net sales])*100)/a.[Previous YTD Net sales])

However, Some customers will have 0 sales either this YTD or last year.

How can I get around this so if either YTD Net Sales or previous YTD equals 0 then just return a 0.

A colleague has told me just to throw a Nullif in front of the calc but thats not working.


I come from a strong excel background, so I would use Iferror(Calc,0) in excel, is there anything similar to this in SQL?

Options: ReplyQuote


Subject
Written By
Posted
Evading Divide by 0 errors
August 07, 2023 02:27AM
August 10, 2023 07:46PM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.