The SQL SQRT Function is one of the Mathematical Function which is used to find the square root of the specified expression or numeric number.

### SQL SQRT() Function Syntax

The basic syntax of the SQRT Function in SQL Server 2014 is as shown below:

1 2 |
SELECT SQRT (Float_Expression) FROM [Source] |

In this article we will show you, How to write SQRT Function in SQL Server 2014 to find the square root with example. For this, We are going to use the below shown data

## SQL SQRT Function Example 1

The SQRT Function in SQL is used to find the square root of a given numeric value. The following query will show multiple ways to use SQRT function.

**T-SQL CODE**

1 2 3 4 5 6 7 8 9 10 |
DECLARE @i float = 4, @j int = 2.20 SELECT SQRT(@i) AS [SQL SQRT] -- Calculating SQRT directly SELECT SQRT(9.90) AS [SQL SQRT] -- Wrong Value SELECT SQRT(@j) AS [SQL SQRT] SELECT SQRT(2.20) AS [SQL SQRT] |

**OUTPUT**

**ANALYSIS**

Below lines of code is used to declare float and int variable and assigning the values.

1 |
DECLARE @i float = 4, @j int = 2.20 |

In the below statement, We used SQRT function to calculate the square root of the variable @i. We also assigned new name to that result as ‘SQL SQRTI’ using SQL ALIAS Column.

1 |
SELECT SQRT(@i) AS [SQL SQRTI] |

It means, √4 = 2

In the next statement, We used the integer value as input for the SQRT function.

1 2 3 |
-- Wrong Value SELECT SQRT(@j) AS [SQLSQRT] SELECT SQRT(2.20) AS [SQL SQRT] |

It means

SQRT (@j) = √2.20 = 1.483

But we are getting 1.4142 as a result because it is rounding the 2.20 value to 2 and the square root of 2 is 1.4142

**NOTE:** Please use float variables as an input for SQRT Function otherwise, you may expect strange results.

## SQL SQRT Function Example 2

The Square Root Function (SQRT) also allows you to find the square root of a column values. In this example, We are going to calculate the square of All the records present in [Sales Amount] using SQRT Function.

**T-SQL CODE**

1 2 3 4 5 6 |
SELECT [EnglishProductName] ,[Color] ,[StandardCost] ,[SalesAmount] ,SQRT([SalesAmount]) AS Sales FROM [Mathemetical Functions] |

**OUTPUT**

Thank You for Visiting Our Blog

## Leave a Reply