Re: Calling DB2 SQL Procedure from SQL Server

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Erland Sommarskog (esquel_at_sommarskog.se)
Date: 08/31/04


Date: Tue, 31 Aug 2004 21:41:09 +0000 (UTC)

Darrell Davis (DarrellDavis@discussions.microsoft.com) writes:
> I'm new to DB2 procedures also, but I believe the procedure works. I
> took it from an example tutorial. Apparently, the DECLARE C1 CURSOR
> WITH RETURN statement indicates that the rows in the cursor C1 will be
> returned from the procedure. Then, apparently, the OPEN C1 statement is
> all that is required to complete the work. When I execute the procedure
> from the DB2 Navigator query tool, it works correctly.
>
> Any other suggestions? I think I am close to getting a solution to my
> problem if I can only figure out how to call the procedure from SQL
> Server.

Rather than using OPENQUERY(), you could try to call the query this way:

   EXEC LINKEDSERVER..NFUHPLIBR.CRPATEST1

and see if this gives you any data back.

I realise that you want to use OPENQUERY, so that you can use the
result in a query, but this is a way to see if SQL Server finds a result
set. And if nothing else works, you could say:
   
   INSERT #temp (col)
      EXEC LINKEDSERVER..NFUHPLIBR.CRPATEST1
      
and then use the temp table.

I don't know about DB2, but you can run into this problem with
OPENQUERY when the linked server is another SQL Server too. The typical
case then is that the stored procedure creates a temp table and then
returns a result set from the temp table. When OPENQUERY invokes SQLOLEDB,
it first runs the query with SET FMTONLY ON, which causes SQL Server to
just sift through the statements to find the result sets, but not execute
the statements. Because of this, the temp table is never created, and no
result set is found.

I have no idea, but it could be something like this that is going here
as well. How you should change the procedure to address that, you are
probably better off asking in a DB2 forum. :-)

-- 
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp


Relevant Pages

  • Re: Proposal: 6NF
    ... SQL SERVER, ORACLE and DB2 have the same heritage then... ... grey areas then they are probably not mathematics. ...
    (comp.databases.theory)
  • Re: IBM releases #1 TPC-E benchmark!
    ... Although I expected you to help discuss temp tables;-) ... DB2 or Oracle? ... And here's poor Serge. ... was Janet in such a rush to release "Viper". ...
    (comp.databases.informix)
  • Re: LEFT OUTER JOIN possible in DB2?
    ... i was trying to get a customer to create a view on their IBM thingy. ... Now, OS/400 comes with its own DBMS, which I assume is at a lower level that an RDBMS, like DB2 or SQL Server. ... > Turns out a LEFT OUTER join is sorta possible in IBM/DB2/AS/400. ...
    (microsoft.public.sqlserver.programming)
  • Re: Whitepaper zu Access 2007
    ... SQL-Server Express oder die MSDEhaben ebenfalls ... zusammengefasste Infos bzgl. Vergleiche SQL Server zu DB2? ... Access FE DB2. ...
    (microsoft.public.de.access)
  • Re: Proposal: 6NF
    ... SQL SERVER, ORACLE and DB2 have the same heritage then... ... Gray has nothing to do with math...At least not the math I am aware ...
    (comp.databases.theory)