SQRT (SQL)
Synopsis
SQRT(numeric-expression)
{fn SQRT(numeric-expression)}
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).
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.
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 }
}