Caché SQL Reference
SQRT
[Back] [Next]
   
Server:docs2
Instance:LATEST
User:UnknownUser
 
-
Go to:
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.
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 of data type NUMERIC, unless numeric-expression is data type DOUBLE, in which case the returned data type is DOUBLE. The returned value has 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