<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN" "http://www.wapforum.org/DTD/wml13.dtd">
<wml>
 <!-- page name="index"-->
 <template>
  <do optional="false" label="Back Up" type="accept">
   <go enctype="application/x-www-form-urlencoded" method="get" sendreferer="true" href="#index"/>
  </do>
 </template>
 <card ordered="true" newcontext="false" id="index">
  <do optional="false" label="Back Up" type="accept">
   <noop/>
  </do>
  <do optional="false" label="Back" type="prev">
   <prev/>
  </do>
  <do optional="false" type="options" label="Next">
   <go enctype="application/x-www-form-urlencoded" method="get" sendreferer="true" href="#db2splinked"/>
  </do>
  <a href="#db2splinked" accesskey="1">DB2 via Linked Server</a>
  <br/>
  <a href="#db2spout" accesskey="2">DB2 Stored Proc.</a>
  <br/>
  <a href="#openquery" accesskey="3">OpenQuery</a>
  <br/>
 </card>
 <card ordered="true" newcontext="false" id="db2splinked">
  <do optional="false" type="options" label="Next">
   <go enctype="application/x-www-form-urlencoded" method="get" sendreferer="true" href="#db2spout"/>
  </do>
  <p align="left">Most examples on the web show that a DB2 stored procedure can be called from SQL Server through a linked server using: </p>
  <p align="left">exec sp_serveroption '<i>db2link</i>', 'rpc', 'true'exec sp_serveroption '<i>db2link</i>', 'rpc out', 'true'declare @in1, @in2, @outvar as char(3)set @in1 = 'ABC'set @in2 = 'GHI'exec <i>db2link</i>..<i>schema</i>.<i>procname</i> @in1, 'DEF', @in2exec <i>db2link</i>.<i>location</i>.<i>schema</i>.<i>procname</i> @in1, 'DEF', @in2exec <i>db2link</i>..<i>schema</i>.<i>procname</i> @in1, 'DEF', @in2, @outvar output</p>
  <p align="left">The rpc and rpc out options can also be set through the linked server proprerties. When <i>location</i> is specified, the stored procedure at that location would be executed through the database at the location specified by <i>db2link</i>. </p>
  <p align="left">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. </p>
  <p align="left">
   <a href="#db2spout">Next: DB2 Stored Proc.</a>
   <br/>
   <a href="#index">Back Up: Menu</a>
   <br/>
  </p>
 </card>
 <card ordered="true" newcontext="false" id="db2spout">
  <do optional="false" type="options" label="Next">
   <go enctype="application/x-www-form-urlencoded" method="get" sendreferer="true" href="#openquery"/>
  </do>
  <p align="left">In order to access the output parameters, the stored procedure must be called in this manner: </p>
  <p align="left">exec sp_serveroption '<i>db2link</i>', 'rpc', 'true'exec sp_serveroption '<i>db2link</i>', 'rpc out', 'true'declare @in1, @in2, @outvar as char(3)set @in1 = 'ABC'set @in2 = 'GHI'exec ('call <i>schema</i>.<i>procname</i>(?,?,?)', @in1, 'DEF', @in2, @outvar output) at <i>db2link</i> exec ('call <i>location</i>.<i>schema</i>.<i>procname</i>(?,?,?)', @in1, 'DEF', @in2, @outvar output) at <i>db2link</i> select @outvar</p>
  <p align="left">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. </p>
  <p align="left">
   <a href="#openquery">Next: OpenQuery</a>
   <br/>
   <a href="#db2splinked">Prev: DB2 via Linked Server</a>
   <br/>
   <a href="#index">Back Up: Menu</a>
   <br/>
  </p>
 </card>
 <card ordered="true" newcontext="false" id="openquery">
  <p align="left">To access the result set: </p>
  <p align="left">select * from openquery(<i>db2link</i>, 'select * from SYSIBM.SYSDUMMY1')select * from openquery(<i>oralink</i>, 'select * from SYS.DUAL')</p>
  <p align="left">
   <a href="#db2spout">Prev: DB2 Stored Proc.</a>
   <br/>
   <a href="#index">Back Up: Menu</a>
   <br/>
  </p>
 </card>
</wml>
