[英]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.