Here, you will see how to use mathematical numeric functions in SQL Server. The Mathematical Numeric functions are based on input values that are provided as arguments, and return a numeric value in SQL Server. We also covered rounding values which can cause confusion to understand and translate them to the correct data type. So let's take a look at a practical example of how to use Mathematical Numeric Functions in SQL Server 2012. The example is developed in SQL Server 2012 using the SQL Server Management Studio.
ABS (number) Function
The ABS Function is used to ignore a negative number or value. This function returns a positive value if any value is not absolute or positive. The Numeric function abs always returns the absolute (positive) value of number.
Example
-- ABS Function
DECLARE @Test int;
SET @Test = -56765;
SELECT ABS(@Test) as absOutput;
SELECT ABS(-11.0) as absOutput, ABS(0.0) as absOutput, ABS(20.0) as absOutput
Output

CEILING (number) Function
The Ceiling Function rounds up a number to the next whole number, regardless of the decimal portion of a number. The ceil function returns the smallest integer value that is greater than or equal to the specified numeric expression.
Example
-- Ceiling Function
select CEILING (125.50)
Select CEILING (-125.30)
Select CEILING (0.30)
Select CEILING (0.05)
SELECT CEILING(4.2 + 9.1)
Output

Floor (number) Function
The Floor Function is the opposite of the ceiling function. The Floor function returns the largest integer value that is greater than or equal to the specified numeric expression or we can say that the Floor function is an expression of the exact numeric or approximate numeric data type category, except for the bit data type.
Example
-- Floor Function
select Floor (125.50)
Select Floor (-125.30)
Select Floor (0.30)
Select Floor (0.05)
SELECT Floor(4.2 + 9.1)
Output

SQUARE (float_number) Function
The Square Function returns the square of the given expression. This function is an important function for when we determine something such as an area of a circle or another calculation which is based on a square. In this function, we also calculate pi()*r^2. R is the radius of circle.
Example
-- Square Function
declare @a int,@b float, @c int






Join the conversation! Your thoughts help the community grow.