I'm brand new to SQL and could use a hand. I'm getting a divide by zero error with the following in my SELECT statement:
SUM(Cast((replace(replace(replace (p.[Total Sales], '$', ''), '(','-'), ')','')) as money)) - SUM(Cast((replace(replace(replace (p.[Total Cost], '$', ''), '(','-'), ')','')) as money)) / SUM(Cast((replace(replace(replace (p.[Total Sales], '$', ''), '(','-'), ')','')) as money)) as new_bal
I know that I need to use CASE, but I'm not sure of the application.
You could use NULLIF in following:
NULLIF(expression1, 0)
In your case It will be: