SQL/MX 3.1 Programming Manual for C and COBOL (H06.23+, J06.12+)
Host Variables in C/C++ Programs
HP NonStop SQL/MX Release 3.1 Programming Manual for C and COBOL—663854-001
3-26
Date-Time and Interval Data
Example
If a database has a BILLINGS table that consists of the CUSTNUM and
BILLING_DATE columns, this example inserts a customer number and date-time value
into that table:
EXEC SQL BEGIN DECLARE SECTION;
struct billing_rec {
unsigned short hv_custnum;
DATE hv_billing_date;
...
} bill;
...
EXEC SQL END DECLARE SECTION;
...
bill.hv_billing_date[10]='\0';
...
EXEC SQL INSERT INTO billings
VALUES (:bill.hv_custnum, :bill.hv_billing_date);
...
Selecting SQL/MP DATETIME Values Not Equivalent to
DATE, TIME, or TIMESTAMP
To retrieve nonstandard SQL/MP DATETIME values that are not equivalent to DATE,
TIME, or TIMESTAMP, declare a C char array one character larger than the number of
characters you expect to store in the array. For a list of nonstandard SQL/MP
DATETIME data types, see the SQL/MX Reference Manual.
Use the SQL/MX CAST function to convert a date-time column in a select list to a
character string. You must also specify the length in the AS clause of the CAST
function to be the length of the declared host variable minus 1. Append a null
terminator to the output character string before you process it as a C character string.
Example
Suppose that an SQL/MP database has a BILLINGS table that consists of the
CUSTNUM and BILLING_DATE columns. The BILLING_DATE column has a
DATETIME MONTH TO DAY data type, which has no equivalent in SQL/MX. This
example selects the SQL/MP DATETIME value:
EXEC SQL BEGIN DECLARE SECTION;
struct billing_rec {
unsigned short hv_custnum;
char hv_billing_date[6];
...
} bill;
...
EXEC SQL END DECLARE SECTION;
...
EXEC SQL SELECT custnum, CAST(billing_date AS CHAR(5))
INTO :bill.hv_custnum, :bill.hv_billing_date
FROM billings
C
C










