SQL/MP Programming Manual for C

Host Variables
HP NonStop SQL/MP Programming Manual for C429847-008
2-12
Fixed-Point Data Types
To select database values into host variables
To refer to values stored in the database for comparisons
The SETSCALE function has this syntax:
host-variable
is an integer host variable.
indicator-variable
is an indicator variable associated with the host variable.
scale
specifies the scale of host-variable. The values for scale depend on the size
of host-variable:
Follow these guidelines when you use the SETSCALE function:
If you are transferring a value from a host variable to a database using an INSERT
or UPDATE statement, you must assign a value to the host variable that allows for
the scale. For example, to insert a price of $123.45, assign 12345 to hostvar and
specify a scale of 2.
If you are retrieving a value from a database using a SELECT statement, NonStop
SQL/MP returns a value that allows for the scale in the host variable. For
example, if your program specifies a scale of 2 in the SELECT statement and
123.45 is stored in the database, SQL/MP returns 12345 to the host variable.
The scale is valid only for SQL statements. If you use the SETSCALE function in
SQL statements and the host variables in calculations using C statements, the
C statements must handle the scale.
To use SETSCALE in an expression, apply the SETSCALE function to each
operand individually rather than to the result of the expression. For example, this
expression adds two prices with a scale of 2 decimal places:
SETSCALE (:price1, 2) + SETSCALE (:price2, 2)
SETSCALE (:host-variable
[ [ INDICATOR ] :indicator-variable ] , scale )
Size Values
2-byte integers 0 – 5 decimal digits
4-byte integers 0 – 10 decimal digits
8-byte integers 0 – 18 decimal digits