SQL/MX 3.2 Programming Manual for C and COBOL (H06.25+, J06.14+)

Static Rowsets
HP NonStop SQL/MX Release 3.2 Programming Manual for C and COBOL663854-002
7-12
Selecting Rows Into Rowset Arrays
If a column in the select list has a nonstandard SQL/MP DATETIME data type that is
not equivalent to DATE, TIME, or TIMESTAMP, use the CAST function to convert the
column to a character string. You must also specify the length of the target host
variable (or the length–1 in the case of a C program) in the AS clause of the CAST
conversion.
For more information on declaring date-time or INTERVAL data types, see Section 3,
Host Variables in C/C++ Programs and Section 4, Host Variables in COBOL Programs.
Examples
This example uses a typical context for selecting a standard date-time value. The
number of rows in the PROJECT table with a start date less than or equal to 1998-12-
01 does not exceed 200:
EXEC SQL BEGIN DECLARE SECTION;
char SQLSTATE[6];
ROWSET [200] unsigned NUMERIC (4) hva_projcode;
ROWSET [200] char hva_projdesc[19];
ROWSET [200] DATE hva_start_date;
...
long numrows;
EXEC SQL END DECLARE SECTION;
long i;
...
EXEC SQL
SELECT projcode, projdesc, start_date
INTO :hva_projcode, :hva_projdesc, :hva_start_date
FROM persnl.project
WHERE start_date <= DATE '1998-12-01';
...
EXEC SQL GET DIAGNOSTICS :numrows = ROW_COUNT;
...
for (i = 0; i < numrows; i++) {
hva_projdesc[i][18] = '\0';
hva_start_date[i][10] = '\0';
printf("\nProject: %hu, %s, Started: %s",
hva_projcode[i], hva_projdesc[i], hva_start_date[i]);
...
/* Process the row in some way. */
....
}
...
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
01 sqlstate pic x(5).
01 numrows pic 9(9) comp.
01 rs.
02 ROWSET[200] hvaprojcode pic 9(4) comp.
02 ROWSET[200] hvaprojdesc pic x(18).
02 ROWSET[200] hvastartdate DATE.
EXEC SQL END DECLARE SECTION END-EXEC.
01 i pic s9(4) comp.
...
EXEC SQL
C
COBOL