What is wrong with this SQL Server query division calculation?

前端 未结 4 1786
梦谈多话
梦谈多话 2020-12-11 23:41

I have this table structure on a SQL Server 2008 R2 database:

  CREATE TABLE FormTest
(   
clientid char(10),
DateSelected date,
A int,
B int,
C int
)
         


        
4条回答
  •  误落风尘
    2020-12-12 00:27

    Dividing integers will result in an integer (The remainder part will be ignored). Hence, when dividing, work with decimals or floats. This should work in addition to the float solutions given earlier. Replace (12,2) with your preferred precision:

    SELECT clientid, (((
    Cast(a as decimal(12,2)) + 
    Cast(b as decimal(12,2)) + 
    Cast(c as decimal(12,2)) 
    ) / 3) / 216647 * 10) AS Formula1 
    FROM FormTest
    

提交回复
热议问题