当值MINUS Null时显示Value而不是Null

时间:2019-11-11 07:47:05

标签: sql

SELECT --PartnerId,
          ScheLineDesc,
          PartNumber,
          TotalQtyOrder,
          TotalShippedQty,
          TotalQtyOrder - TotalShippedQty AS TotalBalanceToShip

enter image description here

当TotalShippedQty为Null时,我需要在TotalBalanceToShip中显示TotalQtyOrder。现在,我只会得到Null。

2 个答案:

答案 0 :(得分:2)

使用coalesce()函数

select ScheLineDesc,
          PartNumber,
          TotalQtyOrder,
          TotalShippedQty,
           coalesce(TotalQtyOrder, 0) - coalesce(TotalShippedQty, 0) as TotalBalanceToShip

答案 1 :(得分:1)

您可以使用IsnullNVL函数检查值并将其替换为null