SQRT() Function in SQL Server
SQRT() function :
This function in SQL Server is used to return the square root of a specified positive number. For example, if the specified number is 81, this function will return 9.
Features :
- This function is used to find the square root of a given number.
- This function accepts only positive numbers.
- This function also accepts fraction numbers.
- This function always returns positive number.
- This function use the formula ”
(a)1/2 = Returned value
“, where a is the specified number.
Syntax :
SQRT(number)
Parameter :
This method accepts a parameter as given below :
- number : Specified positive number whose square root is going to be returned.
Returns :
It returns the square root of a specified positive number.
Example-1 :
Getting the square root of the specified number 4.
SELECT SQRT(4);
Output :
2.0
Example-2 :
Getting the square root of the specified number 0.
SELECT SQRT(0);
Output :
0.0
Example-3 :
Using SQRT() function with a variable and getting the square root of the specified number 1.
DECLARE @Parameter_Value INT; SET @Parameter_Value = 1; SELECT SQRT(@Parameter_Value);
Output :
1.0
Example-4 :
Getting the square root of 16 which is the result of “64/4”.
SELECT SQRT(64/4);
Output :
4.0
Example-5 :
Using SQRT() function with a variable and getting the square root of float value “4.7”.
DECLARE @Parameter_Value FLOAT; SET @Parameter_Value = 4.7; SELECT SQRT(@Parameter_Value);
Output :
2.16794833886788
Application :
This function is used to return the square root of a specified positive number.