SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)
Simple and Compound Statements
HP NonStop SQL/MX Programming Manual for C and COBOL—523627-004
5-15
Assignment Statement
 09-end-compound.
 IF SQLSTATE = SQLSTATE-OK
* Commit the change
 EXEC SQL COMMIT WORK END-EXEC
 ELSE 
* Roll back the change
 EXEC SQL ROLLBACK WORK END-EXEC.
NonStop SQL/MX supports the use of host variables but does not allow for local 
variables declared within the BEGIN and END keywords.
You can use SELECT statements inside compound statements only if each SELECT 
retrieves at most one row (or rowset) result. This restriction is the normal requirement 
for using the SELECT INTO statement. 
Example
Use the SELECT INTO statement to retrieve order information from the database and 
then update the quantity on hand for that part number:
EXEC SQL BEGIN;
 SELECT UNIT_PRICE, QTY_ORDERED 
 INTO :unit_price,:qty_ordered 
 FROM ODETAIL
 WHERE ORDERNUM = :ordernum AND PARTNUM = :partnum;
 UPDATE PARTLOC 
 SET QTY_ON_HAND = QTY_ON_HAND - :qty_ordered 
 WHERE PARTNUM = :partnum AND LOC_CODE = :loc_code;
END;
 EXEC SQL BEGIN
 SELECT UNIT_PRICE, QTY_ORDERED 
 INTO :unit-price,:qty-ordered 
 FROM ODETAIL
 WHERE ORDERNUM = :ordernum AND PARTNUM = :partnum;
 UPDATE PARTLOC
 SET QTY_ON_HAND = QTY_ON_HAND - :qty-ordered
 WHERE PARTNUM = :partnum AND LOC_CODE = :loc-code;
 END END-EXEC.
Assignment Statement
Inside a compound statement, an SQL statement can compute and assign the value of 
an expression to a host variable. Subsequent SQL statements inside that compound 
statement can then use that host variable to get the value of the expression computed 
by the preceding SQL statement. Use this general syntax: 
The target side of the assignment is a list of host variables. The source side of the 
assignment is a value expression, NULL, or a row subquery. 
For complete syntax, see the Assignment statement in the SQL/MX Reference Manual. 
SET assignment-target = assignment-source 
C
COBOL










