SQL Server CEILING

The SQL Server CEILING function is a Mathematical Function. And it is used to return the closest integer value, which is greater than or equal to the specified expression.

The syntax of the SQL CEILING Function is

SELECT CEILING(Numeric_Expression)
FROM [Source]

For this demo, We are going to use the below Table data

Source Table 1

SQL Server CEILING Function Example

The CEILING Function returns the closest integer value, which is greater than or equal to the given numeric value. The following query shows multiple ways to use this.

First, we used it to find the closest integer value of the variable @i. It means -208.45 closest value is -208. In the next SQL Server statement, We have used this Function directly on the integer value.

In the last statement, We used the SQL CEILING Function directly on the multiple values. It means (2.45 + 7.55 – 14.88) = -4.88 = – 4

DECLARE @i float
SET @i = -208.45

SELECT CEILING(@i)AS [SQLCEILING]

-- Calculating directly
SELECT CEILING(0.24)AS [SQLCEILING]

-- Calculating directly
SELECT CEILING(2.45 + 7.55 - 14.88)AS [SQLCEILING]
SQL CEILING Function Value 2

CEILING Example 2

We are going to find the closet integer values for all the records present in [Service Grade] using this Mathematical method.

SELECT [EnglishProductName]
      ,[Color]
      ,CEILING([StandardCost]) AS COST
      ,CEILING([SalesAmount]) AS SALES
      ,CEILING([TaxAmt]) AS TAX
      ,CEILING([Service Grade]) AS Grade
  FROM [Mathemetical Functions]
SQL SERVER CEILING FUNCTION 3

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.