# PRB： 當您在具有除法公式中使用 SUM 或 AVG 函數時，可能會遺失精確度

##### 其他可行方案

• 作為除數的數值。例如：

``DECLARE @Quantity numeric(15,9)SET @Quantity = 3SELECT Round(CAST(Sum(t1.Amount) AS numeric(15,9))/@Quantity, 9) As CostFROM t1					``
• 第一次，將總和儲存在變數，然後在公式中使用該變數。例如：

``declare @quantity numeric (15,9)set @quantity = 3declare @sum numeric (15,9)set @sum= (select sum(amount) from t1)select @sum/@quantity as cost					``
• 將明確值放在為分母。例如：
``select sum(Amount)/3 from t1					``
##### 其他相關資訊

``CREATE TABLE t1 (    Amount    numeric(15,9)    )GOINSERT INTO t1( Amount ) VALUES (0.7)INSERT INTO t1( Amount ) VALUES (1.3)SELECT Amount FROM t1/* result (correct, scale = 9)Amount      ----------------- .7000000001.300000000DECLARE @Quantity numeric(15,9)SET @Quantity = 3    SELECT t1.Amount / @Quantity As CostFROM t1				``

``DECLARE @Quantity numeric(15,9)<BR/>SET @Quantity = 3SELECT Sum(t1.Amount)/@Quantity As Cost<BR/>FROM t1				``

``select sum(Amount)/3 from t1GOselect 2.0000000/@quantity				``

``declare @quantity numeric (15,9)set @quantity = 3declare @sum numeric (15,9)set @sum= (select sum(amount) from t1)select @sum/@quantity as cost				``

#### 警告：本文為自動翻譯

Microsoft SQL Server 7.0 Standard Edition, Microsoft SQL Server 2000 Standard Edition

• kbnosurvey kbarchive kbmt kbprb KB281341 KbMtzh