SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)
Static SQL Cursors
HP NonStop SQL/MX Programming Manual for C and COBOL—523627-004
6-13
Nonstandard SQL/MP DATETIME Example
Nonstandard SQL/MP DATETIME Example
This example shows a typical context for a nonstandard date-time input parameter, 
DATETIME MONTH TO DAY (mm-dd), for a cursor specification:
EXEC SQL BEGIN DECLARE SECTION;
 char SQLSTATE[6];
 unsigned NUMERIC (4) hv_projcode;
 char hv_projdesc[19];
 char hv_start_date[6];
 char in_start_date[6];
EXEC SQL END DECLARE SECTION;...
EXEC SQL DECLARE get_project CURSOR FOR 
 SELECT projcode, projdesc, CAST(start_date AS CHAR(5))
 FROM samdbcat.persnl.project 
 WHERE start_date <= 
 CAST(:in_start_date AS DATETIME MONTH TO DAY);
/* Initialize the value in the WHERE clause. */
printf("Enter latest start date in form mm-dd: ");
scanf("%s", in_start_date);
/* Open the cursor using this value. */ 
EXEC SQL OPEN get_project; 
/* Fetch the first row of the result table. */
EXEC SQL FETCH get_project 
 INTO :hv_projcode,:hv_projdesc,:hv_start_date;
while (strcmp (SQLSTATE, SQLSTATE_NODATA) != 0) {
 /* Process the row in some way. */
 ...
 /* Fetch the next row of the result table. */
 EXEC SQL FETCH get_project 
 INTO :hv_projcode,:hv_projdesc,:hv_start_date;
}
/* Close the cursor. */
EXEC SQL CLOSE get_project;
Interval Example
This example uses a typical context for an interval input parameter for a cursor 
specification:
EXEC SQL BEGIN DECLARE SECTION;
 char SQLSTATE[6];
 unsigned NUMERIC (4) hv_projcode;
 char hv_projdesc[19];
 INTERVAL DAY(4) hv_est_complete;
 INTERVAL DAY(4) in_est_complete;
EXEC SQL END DECLARE SECTION;
...
EXEC SQL DECLARE get_project CURSOR FOR 
 SELECT projcode, projdesc, est_complete
 FROM samdbcat.persnl.project 
 WHERE est_complete <= :in_est_complete 
C
C










