<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="/styles/XMLStylesDoc_xhtml11_en.xsl"?><!DOCTYPE document SYSTEM "/schemas/XMLStyles10.dtd">
<document xmlns="http://XMLStyles.com/namespaces/styles" xmlns:xst="http://XMLStyles.com/namespaces/styles" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:date="http://exslt.org/dates-and-times">
   <noxml>
      <p xmlns="http://www.w3.org/1999/xhtml"/>
      <!-- You are viewing source.  The following message should be ignored if you did "View Source" in your browser. -->
      <p xmlns="http://www.w3.org/1999/xhtml">
ATTENTION: XML WEB PAGES NOT SUPPORTED
   If you see this message, your current browser does not support the
   1999 XSLT 1.0 (or later) standard for XML web pages such as this one.
   Please upgrade your browser to a newer version
   that supports 1999 or later standards such as:
      Mozilla Firefox version 1.0.2 or later (GetFirefox -&gt; http://www.GetFirefox.com/)
      Netscape version 8 or later
      Safari version 1.3 or later
      Opera version 9 or later
      Microsoft Internet Explorer (MSIE) version 5 or later
   For further assistance, contact the software vendor for your browser.
   To go to the X<!-- extended HTML -->HTML version of this page click the following link:
<a href="index.html">index.html</a>
      </p>
      <p xmlns="http://www.w3.org/1999/xhtml">&#160;</p>
   </noxml>
   <path>/computers/databases/sqlserver/</path>
   <site>How To Guides</site>
   <logo xlink:type="simple" xlink:href="/images/howtohome.jpg" media="screen" width="240" height="34">How To Guides</logo>
   <logo xlink:type="simple" xlink:href="/images/howtoguides.jpg" media="print" width="240" height="34">How To Guides</logo>
   <logo xlink:type="simple" xlink:href="/images/howtoguidesmobile.jpg" media="handheld" width="150" height="17">How To Guides</logo>
   <navigation where="sections">
      <label>How To Guides</label>
      <link xlink:type="simple" xlink:href="/business/index.xml">Business</link>
      <link xlink:type="simple" xlink:href="/computers/index.xml">Computers</link>
      <link xlink:type="simple" xlink:href="/computers/databases/index.xml">Databases</link>
      <link xlink:type="simple" xlink:href="/internet/index.xml">Internet</link>
      <link xlink:type="simple" xlink:href="/mobile/index.xml">Mobile</link>
      <link xlink:type="simple" xlink:href="/money/index.xml">Money</link>
      <link xlink:type="simple" xlink:href="/movies/index.xml">Movies</link>
      <link xlink:type="simple" xlink:href="/computers/os/index.xml">Operating Systems</link>
      <link xlink:type="simple" xlink:href="/internet/xml/index.xml">XML</link>
   </navigation>
   <navigation where="up">
      <link xlink:type="simple" xlink:href="../../index.xml">Computers</link>
      <link xlink:type="simple" xlink:href="../index.xml">Databases</link>
   </navigation>
   <navigation where="subsections">
      <link xlink:type="simple" xlink:href="/computers/databases/design.xml">Design</link>
      <link xlink:type="simple" xlink:href="/computers/databases/tuning.xml">Tuning</link>
      <link xlink:type="simple" xlink:href="/computers/databases/ibmdb2/index.xml">IBM DB2</link>
      <link xlink:type="simple" xlink:href="/computers/databases/mysql/index.xml">MySQL</link>
      <link xlink:type="simple" xlink:href="/computers/databases/oracle/index.xml">Oracle</link>
      <link xlink:type="simple" xlink:href="index.xml">SQL Server</link>
   </navigation>
   <section id="body" type="body">
      <pages name="index">
         <title>How To Guides for SQL Server</title>
         <label>SQL Server</label>
         <h>"How To" Guides for Microsoft SQL Server</h>
         <page id="index" name="index">
            <title>Executing Stored Procedures</title>
            <label>Stored Procs.</label>
            <description>Caveats and other information for executing stored procedures from Microsoft SQL Server.</description>
            <navigation where="up">
               <link xlink:type="simple" xlink:href="index.xml">SQL Server</link>
            </navigation>
            <subpage id="N10090" name="db2splinked">
               <label>DB2 via Linked Server</label>
               <h>Executing DB2 Stored Procedures through a SQL Server Linked Server</h>
               <p>Most examples on the web show that a DB2 stored procedure
                  can be called from SQL Server through a linked server using:
               </p>
               <blockcode>
                  <l>exec sp_serveroption '<i>db2link</i>', 'rpc', 'true'</l>
                  <l>exec sp_serveroption '<i>db2link</i>', 'rpc out', 'true'</l>
                  <l>declare @in1, @in2, @outvar as char(3)</l>
                  <l>set @in1 = 'ABC'</l>
                  <l>set @in2 = 'GHI'</l>
                  <l>exec <i>db2link</i>..<i>schema</i>.<i>procname</i> @in1, 'DEF', @in2</l>
                  <l>exec <i>db2link</i>.<i>location</i>.<i>schema</i>.<i>procname</i> @in1, 'DEF', @in2</l>
                  <l>exec <i>db2link</i>..<i>schema</i>.<i>procname</i> @in1, 'DEF', @in2, @outvar output</l>
               </blockcode>
               <p>The <code>rpc</code> and <code>rpc out</code>
                  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>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>
            </subpage>
            <subpage id="N100DD" name="db2spout">
               <label>DB2 Stored Proc.</label>
               <h>Executing DB2 Stored Procedures with Output Parameters</h>
               <p>In order to access the output parameters, the stored procedure must be called in this manner:
               </p>
               <blockcode>
                  <l>exec sp_serveroption '<i>db2link</i>', 'rpc', 'true'</l>
                  <l>exec sp_serveroption '<i>db2link</i>', 'rpc out', 'true'</l>
                  <l>declare @in1, @in2, @outvar as char(3)</l>
                  <l>set @in1 = 'ABC'</l>
                  <l>set @in2 = 'GHI'</l>
                  <l>exec ('call <i>schema</i>.<i>procname</i>(?,?,?)', @in1, 'DEF', @in2, @outvar output) at <i>db2link</i>
                  </l>
                  <l>exec ('call <i>location</i>.<i>schema</i>.<i>procname</i>(?,?,?)', @in1, 'DEF', @in2, @outvar output) at <i>db2link</i>
                  </l>
                  <l>select @outvar</l>
               </blockcode>
               <p>The string passed to the <code>exec</code> command is a native <code>call</code> statement.
                  The question marks are placeholders for the parameters, which are bound to the variables specified in the command.
               </p>
            </subpage>
            <subpage id="N10119" name="openquery">
               <label>OpenQuery</label>
               <h>Accessing the Result Set</h>
               <p>To access the result set:
               </p>
               <blockcode>
                  <l>select * from openquery(<i>db2link</i>, 'select * from SYSIBM.SYSDUMMY1')</l>
                  <l>select * from openquery(<i>oralink</i>, 'select * from SYS.DUAL')</l>
               </blockcode>
            </subpage>
            <updated local="2007-04-20">Friday April 20, 2007</updated>
         </page>
      </pages>
   </section>
   <copyright>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.</copyright>
   <disclaimer>All information, links, forms, applications and other items on this site are provided <b>AS IS</b>. No warranties are expressed or implied.</disclaimer>
   <ids urchin="UA-779578-2"/>
</document>
