docs.intersystems.com
InterSystems IRIS Data Platform 2019.2  /  InterSystems SQL Reference  /  SQL Functions

InterSystems SQL Reference
SQRT
Previous section           Next section
InterSystems: The power behind what matters   
Search:  


A numeric function that returns the square root of a given numeric expression.
Synopsis
SQRT(numeric-expression)

{fn SQRT(numeric-expression)}
Arguments
numeric-expression An expression that resolves to a positive number from which the square root is calculated.
SQRT returns either the NUMERIC or DOUBLE data type. If numeric-expression is data type DOUBLE, SQRT returns DOUBLE; otherwise, it returns NUMERIC.
Description
SQRT returns the square root of numeric-expression. The numeric-expression must be a positive number. A negative numeric-expression (other than -0) generates an SQLCODE -400 error. SQRT returns NULL if passed a NULL value.
SQRT returns a value with a precision of 36 and a scale of 18.
SQRT can be specified as a regular scalar function or as an ODBC scalar function (with the curly brace syntax).
Examples
The following example shows the two SQRT syntax forms. Both return the square root of 49:
SELECT SQRT(49) AS SRoot,{fn SQRT(49)} AS ODBCSRoot
The following embedded SQL example returns the square roots of the integers 0 through 10:
   SET a=0
   WHILE a<11 {
   &sql(SELECT SQRT(:a) INTO :b)
   IF SQLCODE'=0 {
     WRITE !,"Error code ",SQLCODE
     QUIT }
   ELSE {
     WRITE !,"The square root of ",a," = ",b
     SET a=a+1 }
   }
See Also


Previous section           Next section
Send us comments on this page
View this book as PDF   |  Download all PDFs
Copyright © 1997-2019 InterSystems Corporation, Cambridge, MA
Content Date/Time: 2019-09-18 05:38:13