Using host variables

Host variables let you transfer values between Adaptive Server and the application program.

Declare the host variable within the application program’s Embedded SQL declare section. Only then can you use the variable in SQL statements.

When you use the variable within an Embedded SQL statement, prefix the host variable with a colon. When you use the variable elsewhere in the program, do not use a colon. When you use several host variables successively in an Embedded SQL statement, separate them with commas or follow the grammar rules of the SQL statement.

The following example demonstrates how to use a variable. user is defined in a declare section as a character variable. Then, it is used as a host variable in a select statement:

exec sql begin declare section; 
 CS_CHAR  user[32]; 
 exec sql end declare section; 
  
 exec sql select user_name() into :user; 
 printf("You are logged in as %s.\n", user); 

There are four ways to use host variables. Use them as:

Declare all host variables as described in “Declaring variables”, regardless of their function. Following are instructions for using host variables.