Rifa Tabassum
Rifa Tabassum

Reputation: 15

Convert float value to next int value in SQL Server

I want to convert float value into its next integer value like 8.1234 to 9, 7.5678 to 8. I am using ceiling but it's not working, it returns a float value like 7.5, 8.5 in the output.

What is the problem? I don't understand. Someone please help me.

select 
    *,
    (select avg(R) 
     from (values (ceiling(Best1)), (ceiling(Best2))) T (R)) as Average
from 
    result

Upvotes: 0

Views: 246

Answers (1)

ppeterka
ppeterka

Reputation: 20726

You have to execute the ceiling function on the averaged values, not before averaging them.

select *,
    (select ceiling(avg(R)) 
    from ( values Best1, Best2) T (R)) as Average
From result

(Though I can't test this because you didn't provide any test data, and this query also feels syntactically off - but I'm not very deep into MS SQL)

Upvotes: 1

Related Questions