SQL SQRT Function

The SQL SQRT Function finds the square root of the specified expression or numeric number. The syntax of the SQL Server SQRT Function to find the square root is

SELECT SQRT (Float_Expression)
FROM [Source]

For this demo, we use the Mathematical table data

Table Rows 1

SQL Server SQRT Function Example

The SQRT Function finds the square root of a given numeric value. The following Mathematical query will show multiple ways to use this one.

We declared a float and int variable and assigned the values. Next, we used the SQL Server math function to calculate the square root of the variable @i. It means √4 = 2.

Next, we used the integer value as input for the SQRT function.

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

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

SELECT SQRT(@i) AS [SQLSQRT]

-- Calculating directly
SELECT SQRT(9.90) AS [SQLSQRT]

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

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

SQRT Example 2

The SQL Server SQRT Function also allows you to find the square root of column values. Here, We will calculate the square of All the records present in [Sales Amount] using it.

SELECT [EnglishProductName]
      ,[Color]
      ,[StandardCost]
      ,[SalesAmount]
      ,SQRT([SalesAmount]) AS Sales
 FROM [Mathemetical Functions]
SQL SQRT FUNCTION 2
Categories SQL