What is wrong with this SQL Server query division calculation?

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

    You're performing integer arithmetic, so your results will always be rounded down to the nearest whole number. Since you're dividing by 3, then by 216647, based on the numeric inputs your result is getting rounded down to 0 every time. You'll need to use either a decimal (exact) or floating point (approximate) data type and/or casting if you want to get non-integer results.

提交回复
热议问题