Federated procedures for Microsoft SQL Server
Before you create a federated procedure, review which parameters are supported, how result sets are returned, and what limitations exist.
Parameters
Microsoft SQL Server procedures support the use of optional INPUT and OUTPUT parameters. The SQL Server wrapper maps each INPUT parameter to a federated IN parameter and maps each OUTPUT parameter to a federated INOUT parameter. If you use optional parameters in an SQL Server procedure, you must count them when you specify the NUMBER OF PARAMETERS clause of the CREATE PROCEDURE statement.
Result sets
The SQL Server wrapper can return a result set and an OUTPUT parameter. When an SQL Server procedure returns both an OUTPUT parameter and a result set, only the parameter is returned. The result set is discarded, and you receive the SQL0464W error message. The DB2_RETURN_STATUS value is retrieved for procedures that return result sets, but always returns a value of zero (0), regardless of the actual return value from the procedure.
Limitations
- When another procedure is already called
- When another statement is executed during a single connection
DECLARE clientcur CURSOR FOR SELECT colsml,coldec,colvch,coltsp
FROM sql_nick OPEN clientcur; CALL sql_proc();Quick start guide
How to call a stored SQL Server procedure by using Db2 Federation.
Example
CREATE PROCEDURE PROC1 SOURCE BHATIA.PROC1_MSSQL
NUMBER OF PARAMETERS 5 FOR SERVER MSSQL_SERVER
SPECIFIC MYPROC1 WITH RETURN TO CLIENT ALL
MODIFIES SQL DATA DETERMINISTIC EXTERNAL ACTION;- PROC1
- Required. Specifies the name of the federated procedure.
- SOURCE BHATIA.PROC1_MSSQL
- Required. Specifies the name of the schema and procedure on the data source.
- FOR SERVER MSSQL_SERVER
- Required. Specifies a server definition where the federated procedure is created.
- NUMBER OF PARAMETERS 5
- Specifies the total number of IN and OUTPUT parameters that the data source procedure uses.
- SOURCE BHATIA.PROC1_SQL
- Specifies the schema and name for the data source procedure. The format for this two-part name is source_schema_name.source_procedure_name.
- SPECIFIC MYPROC1
- Specifies a unique name for the federated procedure that you are creating. This parameter is used only for federated procedures and is not associated with data source procedures. If you do not specify a unique name, a name is generated by the federated database manager.
- WITH RETURN TO CLIENT ALL
- Specifies that the result set is returned to the client application. Federation returns a maximum of one result set. If this parameter is not specified, the default is WITH RETURN TO CALLER ALL.
- MODIFIES SQL DATA
- Indicates the level of data access for SQL statements that are included in the federated procedure. If the clause specified does not match the data source procedure, an error message is returned. If you do not specify this clause, the clause for the data source procedure is used.
- DETERMINISTIC
- Specifies if the federated procedure always returns the same results for a given set of argument values. This parameter can improve the performance of the interaction between the federated server and the data source.
- EXTERNAL ACTION
- Specifies if the federated procedure takes an action that changes the state of an object that is not managed by the database manager.