07-31-2023, 12:04 AM
I have this error message:
> Msg 8134, Level 16, State 1, Line 1 Divide by zero error encountered.
What is the best way to write SQL code so that I will never see this error message again?
I could do either of the following:
- Add a where clause so that my divisor is never zero
Or
- I could add a case statement, so that there is a special treatment for zero.
Is the best way to use a `NULLIF` clause?
Is there better way, or how can this be enforced?
> Msg 8134, Level 16, State 1, Line 1 Divide by zero error encountered.
What is the best way to write SQL code so that I will never see this error message again?
I could do either of the following:
- Add a where clause so that my divisor is never zero
Or
- I could add a case statement, so that there is a special treatment for zero.
Is the best way to use a `NULLIF` clause?
Is there better way, or how can this be enforced?