2

I was expecting the following SQL Query to return 1

SELECT CEILING(2/10)

However it returns 0. Is there any way to get 1 from that SQL?

Lukasz Szozda
  • 162,964
  • 23
  • 234
  • 275
  • 1
    Possible duplicate of [How to get a float result by dividing two integer values?](https://stackoverflow.com/questions/11719044/how-to-get-a-float-result-by-dividing-two-integer-values) – GSerg May 11 '18 at 14:39

1 Answers1

4

Integer division: 2/10 => 0

If an integer dividend is divided by an integer divisor, the result is an integer that has any fractional part of the result truncated.

You need to change at least one operand to DECIMAL/FLOAT:

SELECT CEILING(2.0/10)
--
SELECT CEILING(CAST(2 AS DECIMAL(10,2))/10)

DBFiddle Demo

Lukasz Szozda
  • 162,964
  • 23
  • 234
  • 275