exec sql

Description

Marks the beginning of a SQL statement embedded in a host language program.

Syntax

exec sql [at connection_name] sql_statement; 

Parameters

at

Causes the SQL statement sql_statement to execute at the Adaptive Server connection connection_name.

connection_name

The connection name that identifies the Adaptive Server connection where sql_statement is to execute. The connection_name must be defined as a previous connect statement.

sql_statement

A Transact-SQL statement or other Embedded SQL statement.

Examples

Example 1

exec sql 
 begin declare section;
     char     site1(20);
     int      sales1;
 exec sql end declare section;
 
 exec sql connect “user1” identified by “password1”
     using “server1”;
 exec sql connect “user2” identified by “password2”
     using “server2”
 /* Remember that a connection that has not been
     explicitly named has the name of its server */
 exec sql at server1 select count(*) from sales
     into :sales1;
 
 site1 = sitename(“server1”);
 exec sql at server2 insert into numsales
     values(:site1, :sales1);

Usage

See also

begin declare section, connect, disconnect, set connection