SQL Reference Guide > SQL Reference Guide > SQL Statements > INQUIRE_SQL > Obtain Logical Key Value with INQUIRE_SQL
Was this helpful?
Obtain Logical Key Value with INQUIRE_SQL
To obtain the last logical key added by an INSERT statement, issue the following INQUIRE_SQL statement:
exec sql inquire_sql
        (:key_variable:null_indicator = key_type)
where:
key_type is OBJECT_KEY or TABLE_KEY.
This inquiry must be issued after an insert that adds a single row containing a logical key. In the case of the INSERT...AS SELECT statement, INQUIRE_SQL (:row_variable=rowcount) can be used to determine the number of rows added. INQUIRE_SQL cannot be used to obtain individual logical key values for multiple rows inserted as the result of an INSERT...AS SELECT statement.
A null indicator variable must be specified when inquiring about logical keys. INQUIRE_SQL returns the following values:
Null Indicator
Key Variable
Returned When..
0
Logical key value
Inquiry is issued after an insert statement that added a single row containing a SYSTEM_MAINTAINED table or object key column.
-1
Unchanged
Inquiry is issued after:
Inserting a row that did not contain the specified type of logical key
A non-insert database statement
An insert that failed, or added either 0 or more than 1 row.
Last modified date: 08/28/2024