SQL/MX 2.x Reference Manual (G06.24+, H06.03+)
SQL/MX Statements
HP NonStop SQL/MX Reference Manual—523725-004
2-209
COBOL Examples of SELECT
COBOL Examples of SELECT 
•
Use a single-row SELECT statement:
EXEC SQL
 SELECT LAST_NAME, FIRST_NAME INTO :hv-lname, :hv-fname 
 FROM EMPLOYEE WHERE EMPNUM = 1234
END-EXEC.
•
This example uses an indicator variable:
 EXEC SQL BEGIN DECLARE SECTION END-EXEC.
 ...
01 ihv-salary PIC S9(4) comp. 
01 hv-salary PIC 9(6)V9(2) comp.
 EXEC SQL END DECLARE SECTION END-EXEC.
 ...
 EXEC SQL
 SELECT SALARY INTO :hv-salary INDICATOR :ihv-salary 
 FROM EMPLOYEE WHERE EMPNUM = 1234
 END-EXEC.
 ...
Publish/Subscribe Examples of SELECT
Suppose that these SQL/MP tables and index (and the metadata mappings) have been 
created:
CREATE TABLE $db.dbtab.tab1 (a int, b int, c int);
CREATE TABLE $db.dbtab.tab2 (a int, b int, c int);
CREATE INDEX $db.dbtab.itab1 ON tab1(b, c);
CREATE SQLMP ALIAS cat.sch.tab1 $db.dbtab.tab1;
CREATE SQLMP ALIAS cat.sch.tab2 $db.dbtab.tab2;
•
These examples show stream access, ordering the access by using an ORDER 
BY clause, and selecting entries by using a WHERE clause:
SET NAMETYPE ANSI;
SET SCHEMA cat.sch;
SELECT * FROM STREAM(tab1);
SELECT * FROM STREAM(tab1) 
WHERE b = 1;
SELECT b, c FROM STREAM(tab1) 
ORDER BY b;
SELECT b, c FROM STREAM(tab1) 
WHERE c > 1 ORDER BY b;
For more information, see ordered streams in SQL/MX Queuing and 
Publish/Subscribe Services.










