Search code examples
sql-server-2008decimalroundingfloor

how to round the decimals to the upper value


i am using sql server 2008 procedure, i have total rows divide by per page, i want that if the results contains any decimal value it should be rounded to its upper value.

i used below:

SELECT FLOOR(@TOTAL / CAST(@PageSize AS FLOAT)) AS TOTALPAGES, @TOTAL AS TOTALROWS

where @total is the float, this does not work. i also tried below

SELECT ROUND(@TOTAL / CAST(@PageSize AS FLOAT),0) AS TOTALPAGES, @TOTAL AS TOTALROWS

This works only when the decimal is >= 5, else it does not take the upper value.

i want that if the results is 12.2 then it should return 13


Solution

  • You need to use the CEILING function. Not ROUND or FLOOR as in your question.