SQRT Function in SQL Server 2008

In this article i will explain how to use SQRT Function in SQL.
  • 2595

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:

sqrt (float_expression)

where float_expression is a float type expression. Return type of SQRT() function is float.

Example

1. SQRT function in select clause.

SQRT (5)

It will return the squareroot of 5 i.e. 2.2360.

Output:

SQRTfunction.jpg


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:

SquareRoot.jpg


Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.