SQRT() Examples in SQL Server

UsingĀ SQL Server, you can use the T-SQL SQRT() function to return the square root of a specified float value.

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

The return data type is float.

Syntax

The syntax goes like this:

SQRT ( 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 SQRT(64) Result;

Result:

+----------+
| Result   |
|----------|
| 8        |
+----------+

And with a different value:

SELECT SQRT(10) Result;

Result:

+------------------+
| Result           |
|------------------|
| 3.16227766016838 |
+------------------+

Example 2 – Negative Value

Negative values will return an invalid floating point operation error.

SELECT SQRT(-64) Result;

Result:

Msg 3623, Level 16, State 1, Line 1
An invalid floating point operation occurred.

Example 3 – Zero

And of course, zero will return zero.

SELECT SQRT(0) Result;

Result:

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

Example 4 – Expressions

You can use expressions such as this:

SELECT SQRT(60 + 4) Result;

Result:

+----------+
| Result   |
|----------|
| 8        |
+----------+