If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Returning Multiple record sets from a stored procedure.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-02-03, 00:50
bgdeepak bgdeepak is offline
Registered User
 
Join Date: Sep 2003
Posts: 14
Returning Multiple record sets from a stored procedure.

Hi,
How can we return multiple recordsets in a stored procedure.
Can i have a sample piece of code on how to do this if this is is possible .

Thanks,
Deepak
Reply With Quote
  #2 (permalink)  
Old 12-02-03, 04:54
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Re: Returning Multiple record sets from a stored procedure.

In the SP header, you have RESULT SETS option to say how many result sets you intend to pass back to the call

Cheers
Sathyaram

Quote:
Originally posted by bgdeepak
Hi,
How can we return multiple recordsets in a stored procedure.
Can i have a sample piece of code on how to do this if this is is possible .

Thanks,
Deepak
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #3 (permalink)  
Old 12-02-03, 05:20
KezbanB KezbanB is offline
Registered User
 
Join Date: Jun 2003
Location: İstanbul
Posts: 19
Re: Returning Multiple record sets from a stored procedure.

Should be something like this :

CREATE PROCEDURE EXAMPLESP (IN examplevar1 INT, OUT examplevar2 INT )
RESULT SETS 2
LANGUAGE SQL
BEGIN
DECLARE cur1 CURSOR WITH RETURN FOR <select .....>;
DECLARE cur2 CURSOR WITH RETURN FOR <select .....>;
.....
OPEN cur1;
OPEN cur2;
END

Like Sathyaram said, RESULT SETS <num> determines how mant result sets will be returned to the caller.
__________________
Kezban
Reply With Quote
  #4 (permalink)  
Old 12-05-03, 05:03
asham asham is offline
Registered User
 
Join Date: Dec 2003
Posts: 3
Question

Thanks for your help on the multiple recordset being returned by a DB2 stored procedure. Now Im facing issue with using this stored procedure in my ASP page through ADO.

Here is a sample of we are tryring to do:

Set oCmd.ActiveConnection = objConn
oCmd.CommandType = adCmdStoredProc
oCmd.CommandText = "myProc.PROC1"
Set objRS = oCmd.Execute
If Not objRS.EOF Then
strArrayDetails = objRS.GetRows
Set objRS = objRS.NextRecordset
If Not objRS.EOF Then
strArrayResponse = objRS.GetRows
End If
Set objRS = objRS.NextRecordset
If Not objRS.EOF Then
strArrayOther = objRS.GetRows
End If
End If

The stored proc is returning 3 result sets. The number of rows in the result sets 2 and 3 are correct but their contents are not. Im getting 3 characters in each field and junk white space characters are appended to the the 3 characters.
We executed the procedure in stored proc builder and we see the correct data. The problem is happening only if we try to display the result sets' contents through ADO in VB/ASP.

Any help ASAP is greatly appreciated,
TIA,
asha
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On