Issue using CEILING in Microsoft SQL

Issue using CEILING in Microsoft SQL

I ran into an issue while doing some report writing for SQL today. I was trying to round up the quotient of one integer divided by another integer. The result never rounded up. What I found was that I had to convert the dividend to a decimal. See my examples:

SELECT
Out1 = 300/24,
Out2 = CONVERT(DECIMAL(14,2), 300)/24

Out1 Out2
———– —————————————
12 12.500000

SELECT
Out1 = CEILING(300/24),
Out2 = CEILING(CONVERT(DECIMAL(14,2), 300)/24)

Out1 Out2
———– —————————————
12 13