Progress
Embedded SQL-92
Guide and Reference


Queries Returning a Single Row

The simplest queries are those that return a single row. When you know that a query is to return a single row, use the INTO clause to receive the result of the query.

EXAMPLE

The following example shows a query against the customer table to retrieve the columns last_name, city, and state:

/*
** Connect to the default database
*/
EXEC SQL CONNECT TO DEFAULT ;
 
EXEC SQL
     SELECT last_name, city, state
     INTO :name_v, :city_v, :state_v
     FROM customer
     WHERE cust_no = 1001 ;
 
if (sqlca.sqlcode < 0)
{
     printf ("Select statement failed (%ld : %s)\n",
             sqlca.sqlcode, sqlca.sqlerrm);
     EXEC SQL ROLLBACK WORK ;
     EXEC SQL DISCONNECT DEFAULT ;
     exit (1);
}
/*
** Successful select. Report results.
*/ printf ("last_name : %s, city : %s, state : %s\n",
     name_v, city_v, state_v);
EXEC SQL COMMIT WORK ;
 
/*
** Disconnect from the default database */
*/
EXEC SQL DISCONNECT DEFAULT ; 

NOTE: If you use SELECT with an INTO clause in a query that returns multiple rows, the operation returns an error message.


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095