What is wrong with this SQL Server query division calculation?

前端 未结 4 1774
梦谈多话
梦谈多话 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:03

    It's because you are doing integer division. You should convert one of the operands to float, or decimal (depending on the precision and purpose of the calculation you are doing), using something like:

    ((CAST((a+ b + c) AS FLOAT) / 3) / 216647 * 10)
    

    or possibly:

    (((a+ b + c) / 3.0) / 216647.0 * 10)
    

提交回复
热议问题