SQUARE() Examples in SQL Server

UsingĀ SQL Server, you can use the T-SQL SQUARE() function to return the square of a specified float value. The square of a number is the result of multiplying the number by itself.

You provide the number as an argument when calling the function.

The return data type is float.

Syntax

The syntax goes like this:

SQUARE ( float_expression )  

Where float_expression is an expression of type float or of a type that can be implicitly converted to float.

Example 1 – Basic Usage

Here’s a basic example to demonstrate.

SELECT SQUARE(4) Result;

Result:

+----------+
| Result   |
|----------|
| 16       |
+----------+

And with a different value:

SELECT SQUARE(10) Result;

Result:

+----------+
| Result   |
|----------|
| 100      |
+----------+

Example 2 – Negative Value

Here’s an example using a negative value.

SELECT SQUARE(-4) Result;

Result:

+----------+
| Result   |
|----------|
| 16       |
+----------+

Example 3 – Zero

And of course, zero will return zero.

SELECT SQUARE(0) Result;

Result:

+----------+
| Result   |
|----------|
| 0        |
+----------+

Example 4 – Expressions

You can use expressions such as this:

SELECT SQUARE(60 + 4) Result;

Result:

+----------+
| Result   |
|----------|
| 4096     |
+----------+

Which is effectively the same as doing this:

SELECT SQUARE(64) Result;

Result:

+----------+
| Result   |
|----------|
| 4096     |
+----------+