我想知道如果除数 = 0,是否有办法不使用除法。在这种情况下,我的查询工作正常,除非它必须除以 0。如果除数是,它应该给出答案为 0 0.有可能吗?这是在 SQL 2005 中。
谢谢!
Select sum(cast(isnull(S.AmountSold, 0) as numeric(10,2))) As DeliveryTotal,
sum(cast(isnull(S.S_AmountCollected, 0) as numeric(10,2))) as DeliveryTotalCollected
(sum(cast(isnull(S.S_AmountCollected, 0) as numeric(10,2))) / sum(cast(isnull(S.AmountSold, 0) as numeric(10,2))) )*100 as DeliveryTotalPercentageCollected
from Info RD