2017-02-07 7 views
1

私はこのようなコードを持つクエリを持っています。算術オーバーフローエラーsqlの数字をデータ型数値に変換する

set @CurrentPatchDeployPercentage = convert(numeric(5,2), (isnull(@LastMonthDeployCount, 0)* 100.00/isnull(nullif(@TotalMachines, 0), 1))) 

私が実行すると、エラーが発生しています。助けてください。

+0

(5,2)の数値5 2分数の意味、5つの総桁数を可能にする - 左の2 = 3の合計桁。計算結果が999.99を超え、エラーが発生します。 numeric() –

+0

のサイズを大きくする数値(5,2)を数値(x、y)に増やすことはできますか?x、yは指定した値よりも相対的に高くなります – balaji

+3

[SQL Serverがスローする理由intをデータ型数値に変換する?](http://stackoverflow.com/questions/2059134/why-sql-server-throws-arithmetic-overflow-error-converting-int-to-data-type-nume) – Tanner

答えて

0

数値データ型に変換する数値の算術オーバーフローエラー、あなたはそれはあなたがあなたの割合を取得したい方法ですか?このような部門の後に*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データ型がとき@TotalMachines = 0ため@LastMonthDeployCount *100.00の最大数をサポートすることができますし、nullに変更し、その後1に変更されていることを確認します。

Decimal/Numeric Data Type - MSDN

Precision Storage bytes 
--------- -------------- 
1 - 9  5 
10-19  9 
20-28  13 
29-38  17 
関連する問題