我有一列通过执行以下计算来计算单位重量 (g)
SELECT ROUND (Weight,0) / nullif ([Units per Carton],0) * 454 AS [Unit Weight (g)]
FROM [Item Master]
我使用 nullif 来消除除以零。但我也想在除数上使用 Round()
我试过这个:
SELECT ROUND (Weight,0) / nullif(Round([Units per Carton],0) * 454) AS [Unit Weight (g)]
FROM [Item Master]
我试过这个:
SELECT nullif (ROUND (Weight,0) / (Round([Units per Carton],0) * 454) AS [Unit Weight (g)]
FROM [Item Master]
错误: 消息 156,级别 15,状态 1,第 1 行关键字“AS”附近的语法不正确。
**那么我如何在除数上将圆形函数与 nullif 结合起来?**
新编辑的代码
SELECT ROUND (Weight,0) / nullif([Units per Carton],0) * 454 AS [Unit Weight (g)]
FROM [Item Master]
SELECT ROUND (Weight / NULLIF([Units per Carton],0),0) * 454 AS [Unit Weight (g)]
FROM [Item Master]
我尝试了上面的方法,我得到的结果在这个->图片中
结果不同,我希望结果为 151、227 和 227,但这些结果被 0 取代。