Retrieves rows from database objects.
exec sql [at connect_name] select select_list into destination from table_name… end-exec
Same as select_list in the Transact-SQL select statement, except that select_list cannot perform variable assignments in Embedded SQL.
A table or a series of one or more Embedded SQL host variables. Each host variable must first be defined in a previous declare section. Indicator variables can be associated with the host variables.
EXEC SQL BEGIN DECLARE SECTION END-EXEC. 01 LNAME PIC X(25). 01 FNAME PIC X(25). 01 PHONE PIC X(15). 01 AU-ID PIC X(12). EXEC SQL END DECLARE SECTION END-EXEC. ... DISPLAY "AUTHOR ID ? ". ACCEPT AU-ID. EXEC SQL SELECT au_lname, au_fname, phone INTO :LNAME, :FNAME, :PHONE FROM authors WHERE au_id = :AU-ID END-EXEC. IF SQLCODE = 100 DISPLAY "COULD NOT LOCATE AUTHOR ",AU-ID ELSE DISPLAY "DETAIL RECORD FOR AUTHOR: ", AU-ID DISPLAY "NAME :",LNAME, " ", FNAME DISPLAY "PHONE :",PHONE END-IF.
This reference page mainly describes aspects of the Transact-SQL select statement that differ when the statement is used in Embedded SQL. See the Adaptive Server Enterprise Reference Manual.
The compute clause of the Transact-SQL select statement cannot be used in Embedded SQL programs.
Host variables in a select statement are input variables only, except in the statement’s into clause. Host variables in the into clause are output variables.
Previously declared input host variables can be used anywhere in a select statement that a literal value or Transact-SQL variable is allowed. Indicator variables can be associated with input host variables to specify null values.
If a select statement returns more than one row, each host variable in the statement’s into clause must be an array with enough space for all the rows. Otherwise, you must use a cursor to bring the rows back one at a time.
declare cursor