我有一个具有这样的代码的查询。
set @CurrentPatchDeployPercentage = convert(numeric(5,2), (isnull(@LastMonthDeployCount, 0)* 100.00 / isnull(nullif(@TotalMachines, 0), 1)))
但是,当我运行时,我遇到了以下错误,请提供帮助。
将数值转换为数值类型的算术溢出错误
您确定那是您想要获得百分比的方式吗?*100.00
这样分割后您应该移动吗?
extrester:http: //rextester.com/NNOEH44668
declare @LastMonthDeployCount numeric(7,2) = 10.00;
declare @TotalMachines numeric (7,2) = 100.00;
declare @CurrentPatchDeployPercentage numeric(9,2);
set @CurrentPatchDeployPercentage =
convert(numeric(5,2),
( isnull(@LastMonthDeployCount, 0)
/
isnull(nullif(@TotalMachines, 0), 1.0)
) * 100.00
);
select @CurrentPatchDeployPercentage;
另外,请确保您的@CurrentPatchDeployPercentage
数据类型可以支持@LastMonthDeployCount *100.00
for的最大数量,@TotalMachines = 0
并且将null
和更改为,然后更改为1
。
Precision Storage bytes
--------- --------------
1 - 9 5
10-19 9
20-28 13
29-38 17
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句