T-SQL Tutorial

T-SQL MATH functions


SQL Server provides a variety of math functions that can be used to perform various calculations and mathematical operations. These functions can be used to manipulate numeric data, perform advanced calculations, and generate statistical information. In this answer, I'll provide an overview of some of the most commonly used math functions in SQL Server.


ABS The ABS function returns the absolute value of a number. For example, ABS(-5) returns 5.

CEILING The CEILING function returns the smallest integer greater than or equal to the specified numeric expression. For example, CEILING(3.25) returns 4.

FLOOR The FLOOR function returns the largest integer less than or equal to the specified numeric expression. For example, FLOOR(3.25) returns 3.

ROUND The ROUND function returns a numeric expression rounded to the specified length or precision. For example, ROUND(3.456, 2) returns 3.46.

SQRT The SQRT function returns the square root of the specified numeric expression. For example, SQRT(16) returns 4.

POWER The POWER function returns the result of raising a number to a specified power. For example, POWER(2, 3) returns 8.

EXP The EXP function returns the exponential value of the specified numeric expression. For example, EXP(1) returns 2.71828.

LOG The LOG function returns the natural logarithm of the specified numeric expression. For example, LOG(10) returns 2.30258.

LOG10 The LOG10 function returns the base-10 logarithm of the specified numeric expression. For example, LOG10(100) returns 2.

PI The PI function returns the value of pi (3.14159).

RAND The RAND function returns a random float value between 0 and 1.

SIGN The SIGN function returns the sign of the specified numeric expression. It returns -1 for negative numbers, 0 for zero, and 1 for positive numbers. For example, SIGN(-5) returns -1.


In addition to these functions, SQL Server also provides a range of statistical functions, such as AVG, COUNT, MAX, MIN, and SUM, which can be used to calculate the mean, median, mode, range, and other statistical measures. These functions are widely used in business intelligence and data analysis applications to extract insights from large datasets.