Add Site or Add Page to Favorites
>

 Executing Stored Procedures 

Preview DRM-free music
Play clips of the most popular DRM-Free music in MP3 format
Legal Music .com

Get information on your favorite TV Shows at TV Series .com

Clarify the meaning of the acronyms on your web site.

Acronym Dictionary

Acronym Finder

Social Networking Web Sites

New Sponsor
Entertainment for Less
Sign up now for this entertainment club and get music CDs, DVDs and video equipment for less.

Register your own domain name at A to Z Domains.

or buy domains at Domain Names For Sale .net



Printer-friendly PDF* format:

Executing Stored Procedures

How To Guides for SQL Server

This Section

Executing DB2 Stored Procedures through a SQL Server Linked Server

Most examples on the web show that a DB2 stored procedure can be called from SQL Server through a linked server using:

exec sp_serveroption 'db2link', 'rpc', 'true'
exec sp_serveroption 'db2link', 'rpc out', 'true'
declare @in1, @in2, @outvar as char(3)
set @in1 = 'ABC'
set @in2 = 'GHI'
exec db2link..schema.procname @in1, 'DEF', @in2
exec db2link.location.schema.procname @in1, 'DEF', @in2
exec db2link..schema.procname @in1, 'DEF', @in2, @outvar output

The rpc and rpc out options can also be set through the linked server proprerties. When location is specified, the stored procedure at that location would be executed through the database at the location specified by db2link.

However, although the driver returns output parameters from the linked server back to SQL Server, output variables are not set when the stored procedure is called this way. Consequently, this works only if the stored procedure has no output parameters, or if the values returned from the stored procedure (such as "@outvar" above) can be ignored, which is a bad thing if success or failure must be determined from those parameters.

Executing DB2 Stored Procedures with Output Parameters

In order to access the output parameters, the stored procedure must be called in this manner:

exec sp_serveroption 'db2link', 'rpc', 'true'
exec sp_serveroption 'db2link', 'rpc out', 'true'
declare @in1, @in2, @outvar as char(3)
set @in1 = 'ABC'
set @in2 = 'GHI'
exec ('call schema.procname(?,?,?)', @in1, 'DEF', @in2, @outvar output) at db2link
exec ('call location.schema.procname(?,?,?)', @in1, 'DEF', @in2, @outvar output) at db2link
select @outvar

The string passed to the exec command is a native call statement. The question marks are placeholders for the parameters, which are bound to the variables specified in the command.

Accessing the Result Set

To access the result set:

select * from openquery(db2link, 'select * from SYSIBM.SYSDUMMY1')
select * from openquery(oralink, 'select * from SYS.DUAL')

Last updated Friday April 20, 2007

You are currently viewing this page in XHTML 1* format (* see Clicklets for more infomation). This document is also available in XHTML 1 Style Sheet*XML* HTML 4*HTML 5 Style Sheet*HTML 5 XML*HTML 5 non-XML* XHTML 2* XHTML Mobile* WML Mobile* and printer-friendly PDF* formats. This is accomplished with Single Source Publishing, a content management system that uses templates in XSLT style sheets provided by XML Styles .com to transform the source content for various content delivery channels. There is also RDF* metadata that describes the content of this document.


Copyright © 2006 How To Guides .com. Alteration of content, including addition of any function such as hypertext links or pop-up advertising, or interference with the hypertext links or other functions of this site is expressly prohibited.

DISCLAIMER: All information, links, forms, applications and other items on this site are provided AS IS. No warranties are expressed or implied.