T-SQL SQUARE() Function
The T-SQL (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:
Data | x |
---|---|
Data 1 | 0.5 |
Data 2 | 1 |
Data 3 | 5 |
Data 4 | 10 |
Data 5 | 50 |
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:
Data | x | SQUARE_Value |
---|---|---|
Data 1 | 0.5 | 0.25 |
Data 2 | 1 | 1 |
Data 3 | 5 | 25 |
Data 4 | 10 | 100 |
Data 5 | 50 | 2500 |
❮ T-SQL Functions