Fault tolerance when zeroing in SQL Sever

xiaoxiao2021-03-06  15

When using such SQL: SELECT A / B AS C from table, it will face the danger of zero-cut, a simple solution is:

SELECT A / B AS C from Table Where B <> 0;

However, this will cause less than the desired data set, often causes errors.

The solution should be:

SELECT CASE WHEN B = 0 THEN NULL ELSE A / B End As C from Table

I didn't know if there is a good statement. It is convenient to write SQL in the future.

转载请注明原文地址:https://www.9cbs.com/read-50467.html

New Post(0)