Skip to content
Advertisement

Division by 0 in SQL Server

How to solve divide by zero problem?

I am trying to calculate profit percentage but getting divide by zero error. I am new and tried all most all forum but couldn’t find any solution. I’m using SQL Server.

Please help me, where I am making mistake?

Above lines are working fine, but this part is causing an issue

I tried to solve this problem like this but still getting errors

Divide by zero error

I tried many possible solution which I found online, including declare and set variable etc. method.

Advertisement

Answer

Use nullif():

This will return null rather than generate an error.

For your particular statement:

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement