Why precision is decreasing when multiply sum to other number

前端 未结 3 580
挽巷
挽巷 2020-12-11 01:51

I have encountered with following bug (or feature) in SQL Server.

When I use SUM (*column*) where column has a numeric(18, 8)

3条回答
  •  长情又很酷
    2020-12-11 02:10

    If you read SUM's reference page, you'll see that on a decimal column it yields a type of NUMERIC(38,6). You need to cast the result of the SUM to NUMERIC(18,8) for it to work the way you want.

    Executing SELECT CAST(SUM(Qnty) as numeric(18,8)) * 2.234 FROM #temp yields 0.00000013404 as you'd expect.

提交回复
热议问题