The SQL Server CEILING function is a Mathematical Function. This CEILING function is used to return the closest integer value, which is greater than or equal to the specified expression. The syntax of the SQL Server CEILING Function is
SELECT CEILING (Numeric_Expression) FROM [Source]
For this CEILING Function demo, We are going to use the below-shown data
SQL Server CEILING Function Example 1
The CEILING Function returns the closest integer value, which is greater than or equal to given numeric value. The following query shows multiple ways to use the CEILING function.
DECLARE @i float SET @i = -208.45 SELECT CEILING(@i)AS [SQL CEILING] -- Calculating CEILING directly SELECT CEILING(0.24)AS [SQL CEILING] -- Calculating CEILING directly SELECT CEILING(2.45 + 7.55 - 14.88)AS [SQL CEILING]
OUTPUT
ANALYSIS
We used the CEILING function to find the closest integer value of the variable @i. CEILING(-208.45) means closest of -208.45
SELECT CEILING(@i)AS [SQL CEILING]
In the next SQL Server statement, We have used this Function directly on the integer value.
SELECT CEILING(0.24)AS [SQL CEILING]
In the below statement, We used the CEILING Function directly on the multiple values.
SELECT CEILING(2.45 + 7.55 - 14.88)AS [SQL CEILING]
It means
CEILING (2.45 + 7.55 – 14.88)
CEILING (-4.88) = – 4
CEILING Function Example 2
We are going to find the closet integer values for all the records present in [Service Grade] using the CEILING Mathematical Function.
SELECT [EnglishProductName] ,[Color] ,CEILING([StandardCost]) AS COST ,CEILING([SalesAmount]) AS SALES ,CEILING([TaxAmt]) AS TAX ,CEILING([Service Grade]) AS Grade FROM [Mathemetical Functions]
OUTPUT