SQL Tutorial SQL Advanced SQL Database SQL References

SQL Server SQUARE() Function



The SQL Server (Transact-SQL) SQUARE() function returns the square of a given number.

Syntax

SQUARE(number)

Parameters

number Required. Specify the number.

Return Value

Returns the square of a given number.

Example 1:

The example below shows the usage of SQUARE() function.

SELECT SQUARE(2);
Result: 4

SELECT SQUARE(3);
Result: 9

SELECT SQUARE(2.5);
Result: 6.25

SELECT SQUARE(-2.5);
Result: 6.25

SELECT SQUARE(SQRT(3));
Result: 2.9999999999999996

Example 2:

Consider a database table called Sample with the following records:

Datax
Data 10.5
Data 21
Data 35
Data 410
Data 550

The statement given below can be used to calculate the square of column x.

SELECT *, SQUARE(x) AS SQUARE_Value FROM Sample;

This will produce the result as shown below:

DataxSQUARE_Value
Data 10.50.25
Data 211
Data 3525
Data 410100
Data 5502500

❮ SQL Server Functions