Static SQL Statements

An entire Transact-SQL transaction, including variable declarations, control-of-flow language, and calls to stored procedures, can be coded as a single static SQL statement.

Static SQL statements can contain C-program host variables for input values and for output data. Host variables are defined by the host C application and are accessible to the C and Embedded SQL sections of your application. For more information about declaring and using host variables, see "Using Host Variables" and "Using the SQLDA Data Structure," later in this chapter.

When an SQL statement uses input host variables, the values of these variables are inserted in the statement before the statement runs. Output host variables are filled with the values that are returned after the statement runs.

Important

Because Embedded SQL does not support alternate format rows, COMPUTE and COMPUTE BY clauses are ignored. If a statement returns multiple results sets, only the first results set is recognized; subsequent results sets are discarded. Also, unless a cursor is used, if a statement returns more than one row, only the first row is recognized; subsequent rows are discarded.

At compile time, static SQL statements can be compiled as stored procedures into an access plan or executed as dynamic SQL statements. (Access plans and their alternatives are described in "Access Plans and Bind Files" and "Building Applications",) When a static SQL statement contains only a single transaction-management command, such as BEGIN TRANSACTION, COMMIT TRANSACTION, ROLLBACK TRANSACTION, or SAVE TRANSACTION, the static SQL statement is not compiled into an access plan because stored procedures cannot contain unbalanced transaction-management statements. In these cases, at run time, the application issues unmatched transaction-management statements as dynamic SQL statements.

The rules for Transact-SQL stored procedures apply to static SQL statements. For more information, see the Microsoft SQL Server Transact-SQL Reference.