Handling stored procedure results

A call to a stored procedure is made through either a remote procedure call, discussed in “Remote procedure call processing”, or a Transact-SQL execute command. The call can generate several types of results. First of all, a stored procedure that contains select statements will return result rows in the usual fashion. Each successive call to dbresults will access the set of rows from the next select statement in the stored procedure. These rows can be processed, as usual, with dbnextrow.

Second, stored procedures can contain “return parameters.” Return parameters, also called output parameters, provide stored procedures with a “call-by-reference” capability. Any change that a stored procedure makes internally to the value of an output parameter is available to the calling program. The calling program can retrieve output parameter values once it has processed all of the stored procedure’s result rows by calling dbresults and dbnextrow. A number of routines, described below, process return parameter values.

Third, stored procedures can return a status number.

To access a stored procedure’s output parameters and return status through the following routines: