SQL Programming Manual for TAL

NonStop SQL Statements and Directives
HP NonStop SQL Programming Manual for TAL527887-001
3-33
SELECT
EXEC SQL BEGIN DECLARE SECTION; ! Variable declarations
STRUCT customer^type;
BEGIN
INT custnum;
STRING custname[0:17];
STRING street[0:21];
STRING city[0:13];
STRING state[0:11];
STRING postcode[0:9];
END;
STRUCT .customer(customer^type);
INT find^this^customer;
EXEC SQL END DECLARE SECTION;
PROC handle^not^found; FORWARD;
EXEC SQL WHENEVER NOT FOUND CALL :handle^not^found;
...
PROC find^record;
BEGIN
find^this^customer := 5635;
EXEC SQL
SELECT custname, street, city, state, postcode
INTO :customer.custname,:customer.street,:customer.city,
:customer.state, :customer.postcode
FROM sales.customer
WHERE customer.custnum = :find^this^customer
BROWSE ACCESS;
... ! Print values in host variables
END; ! end of find^record
PROC driver MAIN;
BEGIN
CALL find^record;
END;
...
Using a Primary Key Value. This example shows a SELECT statement that selects a
row using a primary key column.
EXEC SQL
SELECT column2,
column3,
column4
INTO :host^var2,
:host^var3,
:host^var4
FROM mytable
WHERE column1 = :host^varkey ;
In this example, the WHERE clause specifies that the selected row contains a primary
key, COLUMN1, whose value is equal to the value of a specified host variable. Only
one row is retrieved from the table because a unique primary key value is used for the
selection.