SQL/MP Programming Manual for C
Data Retrieval and Modification
HP NonStop SQL/MP Programming Manual for C—429847-008
4-5
Using a Column Value to Select Data
NonStop SQL/MP returns these values to sqlcode after a SELECT statement:
For more information about sqlcode, see Section 9, Error and Status Reporting.
Using a Column Value to Select Data
This SELECT statement returns a row containing a customer’s name and address
based on the unique value of a column (a nonkey value). Each customer is identified
by a unique number so that only one customer satisfies the query. This example uses
a WHERE clause to specify that the CUSTOMER.CUSTNAME column contains a
unique value equal to the host variable find_this_customer. (This example sets
find_this_customer to customer number 5635 using an assignment statement,
but in a typical application, a user would enter the number.)
EXEC SQL BEGIN DECLARE SECTION;
struct customer_type /* host variables */
{
short custnum;
char custname[19];
char street[23];
char city[15];
char state[13];
char postcode[11];
} customer;
int find_this_customer;
EXEC SQL END DECLARE SECTION;
...
...
void not_found_function(void) /* For NOT FOUND condition */
{
...
}
void find_record(void)
{
find_this_customer = 5635;
EXEC SQL SELECT customer.custname,
customer.street,
customer.city,
customer.state,
customer.postcode
INTO :customer.custname,
:customer.street,
:customer.city,
:customer.state,
sqlcode Value Description
0 The SELECT statement was successful.
100 No rows qualified for the SELECT statement specification.
<0 An error occurred;
sqlcode contains the error number.
>0 (¦100) A warning occurred;
sqlcode contains the warning number.