SQL/MX 2.x Reference Manual (H06.04+)

SQL/MX Statements
HP NonStop SQL/MX Reference Manual540440-003
2-161
MXCI Examples of PREPARE
If you do not specify a name for a static SQL statement, the SQL 3GL preprocessor
assigns the statement a name of the form SQLMX_DEFAULT_STATEMENT_n, where
n is an integer incremented by the preprocessor.
Statement Names
You cannot have more than one statement allocated with the same name within the
same scope. For example, this sequence from a C program is not valid:
strcpy(stmt1,"STMT1");
EXEC SQL PREPARE :stmt1 FROM :stmt_buffer1;
...
strcpy(stmt2,"STMT1");
EXEC SQL PREPARE :stmt2 FROM :stmt_buffer2;
The second PREPARE fails because STMT1 has already been prepared.
MXCI Examples of PREPARE
Prepare a SELECT statement, naming it FINDEMP, and then execute FINDEMP:
PREPARE FINDEMP FROM
SELECT * FROM persnl.employee
WHERE salary > 40000.00 AND jobcode = 450;
--- SQL command prepared.
EXECUTE findemp;
EMPNUM FIRST_NAME LAST_NAME DEPTNUM JOBCODE SALARY
------ ---------- ---------- ------- ------- --------
232 THOMAS SPINNER 4000 450 45000.00
--- 1 row(s) selected.
Prepare a SELECT statement, naming it EMPCOM, and then enter the DISPLAY
STATISTICS command to display the preparation statistics:
PREPARE EMPCOM FROM
SELECT first_name, last_name, deptnum
FROM persnl.employee
WHERE deptnum <> 1500
AND salary <= (SELECT AVG (salary)
FROM persnl.employee
WHERE deptnum = 1500);
--- SQL command prepared.
DISPLAY STATISTICS;
Start Time 2000/04/24 15:09:39.439
End Time 2000/04/24 15:09:46.946
Elapsed Time 00:00:07.507
Compile Time 00:00:07.507
Execution Time 00:00:00.000
C/COBOL