| |

VerySource

 Forgot password?
 Register
Search
View: 1477|Reply: 13

How to shield from a division by zero error!

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-19 00:00:01
| Show all posts |Read mode
How to shield from a division by zero error!
Because the value of the expression is applied to the dynamic SQL (such as exec sp_executesql @ sql, N '@ va numeric (18,6) output', @ va output),
There is a division operation in the expression, and there may be a division by zero, and the program will exit. How can this mask the error?
Write 0 to the result to continue running?
Reply

Use magic Report

0

Threads

114

Posts

69.00

Credits

Newbie

Rank: 1

Credits
69.00

 China

Post time: 2020-1-25 15:18:02
| Show all posts
Judging before the case when field = 0 then 0 else ...
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 China

Post time: 2020-1-25 15:36:01
| Show all posts
Doesn't seem to work
Reply

Use magic Report

0

Threads

114

Posts

69.00

Credits

Newbie

Rank: 1

Credits
69.00

 China

Post time: 2020-1-25 17:54:01
| Show all posts
Then divide it into 2 checks. Where <> 0
Union all again.
Reply

Use magic Report

0

Threads

20

Posts

19.00

Credits

Newbie

Rank: 1

Credits
19.00

 China

Post time: 2020-1-25 18:18:02
| Show all posts
Add a case when ... else ... end
Reply

Use magic Report

0

Threads

49

Posts

35.00

Credits

Newbie

Rank: 1

Credits
35.00

 China

Post time: 2020-1-26 06:18:01
| Show all posts
Support upstairs!
Reply

Use magic Report

0

Threads

93

Posts

46.00

Credits

Newbie

Rank: 1

Credits
46.00

 China

Post time: 2020-1-26 06:36:02
| Show all posts
The dividend is 0
Define in the dividend (case when value = 0 then 1 else value end)
Reply

Use magic Report

0

Threads

14

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-1-26 12:09:02
| Show all posts
At the beginning of the query, add
set ansy_warnings off
This will not interrupt the query error when divided by 0, but will return null for the field divided by 0
Reply

Use magic Report

0

Threads

14

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-1-26 12:27:01
| Show all posts
sorry, yes
SET ansi_warnings OFF
Reply

Use magic Report

0

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-1-26 18:18:02
| Show all posts
Add a judgment to the division operation: case when the divisor> 0 then the dividend / divider else 0 end
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list