June 7, 2006 at 8:58 am
Hi,
I have a problem retrieving output parameters from calling procedura with
declare @OutputParameter varchar(100) ,
@OutputParameter2 varchar(100) ,
@StoreProc varchar(128) ,
@StoreProcCall nvarchar(128) ,
@rc int
select @StoreProcCall = 'exec ' + @StoreProc + ' @OutputParameter1 output, @OutputParameter2 output'
exec @rError = sp_executesql @StoreProcCall, N'@OutputParameter varchar(100) output', @OutputParameter output, N'@OutputParameter2 varchar(100) output', @OutputParameter2 output
The problem is that running it, i have this error in query analyzer:
Server: Msg 137, Level 15, State 2, Line 1
Must declare the variable OutputParameter2 .
OuuPuts are already declared !
Anyone can help me ?
Thank
June 7, 2006 at 9:35 am
The issue is the 2 levels of indirect references to exec sp_executeSQL. Let's see the final statement that is executed - each level of indent indicating another context
declare @OutputParameter varchar(100) ,
@OutputParameter2 varchar(100) ,
@StoreProc varchar(128) ,
@StoreProcCall nvarchar(128) ,
@rc int
exec @rError = sp_executesql @StoreProcCall [...]
**** whoops - no output parameters defined at this level!
exec sp_executeSQL , @OutputParameter1 output, @OutputParameter2 output
, @OutputParameter1 output, @OutputParameter2 output
The OutputParameter1 and 2 values are not defined in the context of the second EXEC call. Thus, the error.
Why not just one level of EXEC?
June 7, 2006 at 10:03 am
I have re-written the statement,
declare @OutputParameter varchar(100) ,
@OutputParameter2 varchar(100) ,
@StoreProc varchar(128) ,
@StoreProcCall nvarchar(128) ,
@rc int
select @StoreProcCall = 'exec @rError=' + @StoreProc + ' @OutputParameter1 output, @OutputParameter2 output'
exec sp_executesql @StoreProcCall, N'@OutputParameter varchar(100) output, @OutputParameter2', @OutputParameter , @OutputParameter2
it is executed without error, but I do not retrieve output, they are null ???
Thank
June 7, 2006 at 10:19 am
Okay - let's break this down.
exec @rError = @StoreProc @OutputParameter1 output, @OutputParameter2 output
Run just this segment, and give the values in @rcError, @outputparameter1, and @outputparameter2.
--------------------------------------------------------------
Declare @StoreProc varchar(64)
SET @StoreProc = '[whatever]'
Declare @OutputParameter varchar(100)
Declare @OutputParameter2 varchar(100)
Declare @rError int
exec @rError = @StoreProc @OutputParameter output, @OutputParameter2 output
Select @rError As ReturnVal, @OutputParameter as OutParm1, @OutputParameter2 as OutParm2
--------------------------------------------------------------
What values are returned?
June 7, 2006 at 11:20 am
proc testprocparams @OutputParameter1 int output, @OutputParameter2 int output
@OutputParameter int,@OutputParameter2 int ,@StoreProc varchar(128) ,
@rc = sp_executesql @StoreProcCall, N'@OutputParameter1 int output, @OutputParameter2 int output', @OutputParameter output, @OutputParameter2 output
Tim Wilkinson
"If it doesn't work in practice, you're using the wrong theory"
- Immanuel Kant
June 7, 2006 at 2:21 pm
Thank to everybody,
I'll try your suggestion ...
thank
June 8, 2006 at 3:01 am
OK,
I have resolved the problem, I forgot to add OUTPUT after the OutPutParameters.
Thank
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply