The precompiler does not generate stored procedures
for dynamic SQL statements because the statements are not complete
until runtime. At runtime, Adaptive Server stores them as temporary
stored procedures in the tempdb database. The tempdb database
must contain the user name "guest", which in turn
must have create procedure permission. Otherwise,
attempting to execute one of these temporary stored procedures generates
the error message "Server user id user_id is
not a valid user in database database_name",
where user_id is the user’s
user ID, and database_name is the
name of the user’s database.
The dynamic SQL prepare statement sends the actual SQL statement, which can be any Data Definition Language (DDL) or Data Manipulation Language (DML) statements or any Transact-SQL statement, except create procedure, to the server.
The dynamic SQL facility performs these actions:
Translates the input data into a SQL statement.
Verifies that the SQL statement can execute dynamically.
Prepares the SQL statement for execution, sending it to Adaptive Server, which compiles and saves it as a temporary stored procedure (for methods 2, 3, and 4).
Binds all input parameters or descriptor (for methods 2, 3, and 4).
Executes the statement.
For a varying-list select, it uses a descriptor to reference the data items and rows returned (for method 2 or 4).
Binds the output parameters or descriptor (for method 2, 3, or 4).
Obtains results (for method 2, 3, or 4).
Drops the statement (for methods 2, 3, and 4) by reactivating the stored procedure in Adaptive Server.
Handles all error and warning conditions from Adaptive Server and Client-Library.