Using Static and Dynamic Statements

Embedded SQL supports both static and dynamic SQL statements. Static SQL statements can be placed into stored procedures. Dynamic SQL statements are built and executed at run time.

A static SQL statement is a complete Transact-SQL statement that is embedded in the program source code. Static SQL statements can contain host variables.

A dynamic SQL statement is an incomplete Transact-SQL statement, some or all of which is supplied at run time.

With dynamic SQL statements, knowing the complete structure of an SQL statement before building the application is not necessary. Dynamic SQL statements allow run-time input to provide information about the database objects to query.

Dynamic SQL statements that are created by using the PREPARE and EXECUTE statements can contain parameter markers and host variables. Parameter markers are question marks (?) that act as placeholders for information that is supplied at run time. Dynamic SQL statements that are executed using the EXECUTE IMMEDIATE statement must conform to Transact-SQL language rules. They cannot contain parameter markers, host variables, or keywords that pertain exclusively to Embedded SQL.