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:
dbnumrets – returns the number of return parameter values generated by a stored procedure. If dbnumrets returns less than or equal to zero, no return parameter values are available.
dbretdata – returns a pointer to a return parameter value.
dbretlen – returns the length of a return parameter value.
dbrettype – returns the datatype of a return parameter value.
dbretname – returns the name of the return parameter associated with a particular value.
dbretstatus – returns the stored procedure’s status number.
dbhasretstat – indicates whether the current command or remote procedure call generated a stored procedure status number. If dbhasretstat returns “FALSE,” then no stored procedure status number is available.