SQRT Function in SQL Server 2008
In this article i will explain how to use SQRT Function in SQL.
Introduction
SQRT() is mathematical function. It is used to return the square root of the given expression. It takes one argument whose squareroot value is to be find. Basic syntax of SQRT function is described below.
Syntax:
where float_expression is a float type expression. Return type of SQRT() function is float.
Example
1. SQRT function in select clause.
It will return the squareroot of 5 i.e. 2.2360.
Output:
2. Return the square root of numbers from 1 to 5
declare @number float;
SET @number = 1.00;
WHILE @number <= 5.00
BEGIN
SELECT SQRT(@number);
SET @number = @number + 1
END;
GO
|
Select all code and press F5 to run above code.
Output: