Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stored proc calling another stored proc with output?

Status
Not open for further replies.

jtseltmann

Programmer
Jan 15, 2002
149
US
I have one main stored proc that sets a table variable and then loops through the records. After setting the vars I call my other proc that has an output param I need.

As I perform the loop...the input to the 2nd proc changes and I expect the output param to change was well. I can verify this also by printing my vars. It seems the call to the proc to get the output is happening once. One of the records in my set should return an error text and it isn't. If I make my loop select only pull that one record then it works but if it pulls all 150 it doesn't.

I have tried everything from calling the proc and hard coding the values. When I do this by itself, it works and the error text is returned. When I add it back and call the proc as I loop through records it never finds the bad rec.

I'm relatively new to sql proc programming but I cannot figure this one out. I can post sample code if you like. My code works perfectly except for the one var I set using the output from this second proc.

Is there some problem calling a proc within proc? NO right?

ANy help or suggestions would be great! Thanks!
 
Thank you..i figured. The problem I found was that it seems SQL requires that you reset the output parameter to '' before each call to the proc that you want it returned from.

e.g. in the proc below if you don't reset @output1 = '' before each call the param is not set. It is the same value as the first time you called no matter what you do to the input parameter.

---------------------------
DELCARE @output1 varchar(30)

WHILE @rowcount <= @totalrows
BEGIN
SET @input1 = 'something'
SET @output1 = '' --<this is what I was missing
EXEC sp_getinfo @input1, @output1 OUTPUT
END
END
-----------------------------

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top