このようなコードを持つクエリがあります。
set @CurrentPatchDeployPercentage = convert(numeric(5,2), (isnull(@LastMonthDeployCount, 0)* 100.00 / isnull(nullif(@TotalMachines, 0), 1)))
しかし、実行するとエラーが発生します。助けてください。
数値をデータ型数値に変換する算術オーバーフローエラー
それがあなたのパーセンテージを取得したい方法であると確信していますか?*100.00
このように分割した後、移動する必要がありますか?
rextester: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
たときのため@TotalMachines = 0
に変更されnull
、その後に変更を1
。
Precision Storage bytes
--------- --------------
1 - 9 5
10-19 9
20-28 13
29-38 17
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加