[英]How to handle Divide by zero Error in SQL query
在 sql server 中运行以下 sql 查询。
Select id, description, cost, price, ((price-cost)/price) as Margin
from item
我收到此错误消息。
Msg 8134, Level 1, State 1, Line 1
Divide by zero error encountered.
价格和成本的值即使在减去它们大于零后也大于零。 不明白为什么我收到错误消息。
使用nullif(price,0)
Select id, description, cost, price, (price-cost)/nullif(price,0) as Margin from item
尝试使用 NULL 函数
使用 NULIF(price,0)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.