SQL SIGN Function

Example

Return the sign of a number:

SELECT SIGN(255.5);

Definition and Usage

The SIGN() function returns the sign of a number.

This function will return one of the following:

  • If number > 0, it returns 1
  • If number = 0, it returns 0
  • If number < 0, it returns -1

Syntax

SIGN(number)

Continue reading SQL SIGN Function

SQL ROUND Function

Example

Round the number to 2 decimal places:

SELECT ROUND(235.415, 2) AS RoundValue;

Definition and Usage

The ROUND() function rounds a number to a specified number of decimal places.

Tip: Also look at the FLOOR() and CEILING() functions.

Syntax

ROUND(number, decimals, operation)

Continue reading SQL ROUND Function

SQL RAND Function

Example

Return a random decimal number (no seed value – so it returns a completely random number >= 0 and <1):

SELECT RAND();

Definition and Usage

The RAND() function returns a random number between 0 (inclusive) and 1 (exclusive).

Syntax

RAND(seed)

Continue reading SQL RAND Function

SQL POWER Function

Example

Return 4 raised to the second power:

SELECT POWER(4, 2);

Definition and Usage

The POWER() function returns the value of a number raised to the power of another number.

Syntax

POWER(a, b)

Continue reading SQL POWER Function

SQL PI Function

Example

Return the value of PI:

SELECT PI();

Definition and Usage

The PI() function returns the value of PI.

Note: Also look at the DEGREES() and RADIANS() functions.

Syntax

PI()

Continue reading SQL PI Function

SQL MIN Function

Example

Find the price of the cheapest product in the “Products” table:

SELECT MIN(Price) AS SmallestPrice FROM Products;

Definition and Usage

The MIN() function returns the minimum value in a set of values.

Note: Also look at the MAX() function.

Syntax

MIN(expression)

Continue reading SQL MIN Function

SQL MAX Function

Example

Find the price of the most expensive product in the “Products” table:

SELECT MAX(Price) AS LargestPrice FROM Products;

Definition and Usage

The MAX() function returns the maximum value in a set of values.

Note: Also look at the MIN() function.

Syntax

MAX(expression)

Continue reading SQL MAX Function

SQL LOG10 Function

Example

Return the base-10 logarithm of 2:

SELECT LOG10(2);

Definition and Usage

The LOG10() function returns the natural logarithm of a number to base 10.

Note: Also look at the LOG() function.

Syntax

LOG10(number)

Continue reading SQL LOG10 Function

SQL LOG Function

Example

Return the natural logarithm of 2:

SELECT LOG(2);

Definition and Usage

The LOG() function returns the natural logarithm of a specified number, or the logarithm of the number to the specified base.

From SQL Server 2012, you can also change the base of the logarithm to another value by using the optional base parameter.

Note: Also look at the EXP() function.

Syntax

LOG(number, base) — Syntax for SQL Server

OR :

LOG(number) — Syntax for Azure SQL Database, Azure SQL Data Warehouse, Parallel Data Warehouse

Continue reading SQL LOG Function