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

Host Variables in C/C++ Programs
HP NonStop SQL/MX Release 3.2 Programming Manual for C and COBOL663854-002
3-35
Date-Time and Interval Data
Example
A database contains a BILLINGS table consisting of the CUSTNUM, START_DATE,
BILLING_DATE, and TIME_BEFORE_PMT columns. This example selects a customer
number and interval value:
EXEC SQL BEGIN DECLARE SECTION;
struct billing_rec {
unsigned short hv_custnum;
DATE hv_start_date;
DATE hv_billing_date;
INTERVAL DAY(3) hv_time_before_pmt;
} bill;
...
EXEC SQL END DECLARE SECTION;
...
EXEC SQL SELECT custnum, time_before_pmt
INTO :bill.hv_custnum, :bill.hv_time_before_pmt
FROM billings
WHERE custnum = :hv_this_customer;
... bill.hv_time_before_pmt[4]='\0';
Inserting or Updating Interval Values
To insert or update interval values, format a C interval string in the desired display
format for an interval. The first character is reserved for the sign of the interval.
Example
A database contains a BILLINGS table consisting of the CUSTNUM, START_DATE,
BILLING_DATE, and TIME_BEFORE_PMT columns. This example updates date-time
and interval values:
EXEC SQL BEGIN DECLARE SECTION;
struct billing_rec {
unsigned short hv_custnum;
DATE hv_start_date;
DATE hv_billing_date;
INTERVAL DAY(3) hv_time_before_pmt;
} bill;
...
EXEC SQL END DECLARE SECTION;
...
bill.hv_start_date[10]='\0'
bill.hv_billing_date[10]='\0';
/* Blank pad if the interval data is less than 3 digits. */
...
strcpy(bill.hv_time_before_pmt," 111");
EXEC SQL UPDATE billings
SET billing_date = :bill.hv_billing_date,
time_before_pmt = :bill.hv_time_before_pmt
WHERE custnum = :hv_this_customer;
...
C
C