SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)
Simple and Compound Statements
HP NonStop SQL/MX Programming Manual for C and COBOL—523627-004
5-3
Selecting a Column With Date-Time or INTERVAL
Data Type
 02 CUSTNUM PIC 9(4) COMP.
 02 CUSTNAME PIC X(18).
 02 STREET PIC X(22).
 02 CITY PIC X(14).
 02 STATE PIC X(12).
 02 POSTCODE PIC X(10).
 01 FIND-THIS-CUSTOMER PIC 9(4) COMP.
EXEC SQL END DECLARE SECTION END-EXEC.
 PROCEDURE DIVISION.
 0000-BEGIN.
 EXEC SQL 
 WHENEVER NOT FOUND PERFORM 4000-NOT-FOUND 
 END-EXEC.
 ...
* Accept input value for host variable in WHERE clause. 
 ...
 EXEC SQL
 SELECT custname, street, city, state, postcode
 INTO :CUSTNAME, :STREET, :CITY, :STATE, :POSTCODE
 FROM sales.customer
 WHERE custnum = :FIND-THIS-CUSTOMER
 END-EXEC.
 ...
 DISPLAY CUSTNAME, STREET, CITY, STATE, POSTCODE.
 ...
 4000-NOT-FOUND.
 DISPLAY "CUSTOMER NOT FOUND:" FIND-THIS-CUSTOMER.
Selecting a Column With Date-Time or INTERVAL Data Type
If a column in the select list has an INTERVAL or standard date-time (DATE, TIME, 
TIMESTAMP, or the SQL/MP DATETIME equivalents) data type, use the INTERVAL or 
date-time types. If your C program performs string operations on date-time and 
INTERVAL host variables, you need to null terminate the date-time and INTERVAL 
host variables. For information on null termination, see Fixed-Length Character Data 
on page 3-14. 
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. 
Standard Date-Time Example
This example uses a typical context for selecting a date-time value:
EXEC SQL BEGIN DECLARE SECTION;
 char SQLSTATE[6];
 unsigned NUMERIC (4) hv_projcode;
 char hv_projdesc[19];
 DATE hv_start_date;
C










