Method 2: Using prepare and execute

Use method 2, prepare and execute, when one of the following cases is true:

This process is also called a single-row select. If a user needs to retrieve multiple rows, use method 3 or 4.

This method uses prepare and execute to substitute data from COBOL variables into a Transact-SQL statement before sending the statement to Adaptive Server Enterprise. The Transact-SQL statement is stored in a character buffer with dynamic parameter markers to show where to substitute values from COBOL variables.

Because this statement is prepared, Adaptive Server Enterprise compiles and saves it as a temporary stored procedure. Then, the statement executes repeatedly, as needed, during the session.

The prepare statement associates the buffer with a statement name and prepares the statement for execution. The execute statement substitutes values from a list of COBOL variables into the buffer and sends the completed statement to Adaptive Server Enterprise. You can execute any Transact-SQL statement this way.