,(CAST(SUM(Y.[Profit]) AS DECIMAL (18,2)) / CAST(SUM(Y.[Sales]) AS DECIMAL (18,2))) AS 'AHT'
有没有人知道我把ISNULL或NULLIF放在哪里,这样我就不会遇到"除以零错误遇到"的错误?
我期望看到NUll或Zero (0)
您需要在操作前检查除数,例如:
CASE
WHEN SUM(Y.[Sales]) != 0
THEN (CAST(SUM(Y.[Profit]) AS DECIMAL (18,2)) / CAST(SUM(Y.[Sales]) AS DECIMAL (18,2)))
ELSE NULL
END AS 'AHT'