Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling one stored procedure within another stored procedure using variables from first stored procedure

I have a stored procedure say @Create_Dummy1 which is being passed a variable. This is declared as @Dummy_Variable1 in this stored procedure.

Next I need to call another stored procedure @Create_Dummy2 from @Create_Dummy1. I need to pass @Dummy_Variable1 in the exec statement.

But if I try to do this the string @Dummy_Variable1 is only being passed instead of the value it holds.

like image 514
Shruti Avatar asked Oct 11 '12 07:10

Shruti


2 Answers

I'm executing procedures inside other procedures like this:

DECLARE @childResult int, @loaErrorCode int, @loaErrorMessage varchar(255) 
EXEC @childResult = [dbo].[proc_sub_getSomething] @schemes_id = @foo_schemes_i, @errorCode = @loaErrorCode OUTPUT , @errorMessage = @loaErrorMessage OUTPUT

Should it still not work you should edit your question to show your exact code.

like image 126
ExternalUse Avatar answered Oct 14 '22 08:10

ExternalUse


This should work:

create procedure Create_Dummy1
(
    @Dummy_Variable1  int
)
as 

exec Create_Dummy2 @Dummy_Variable1

Go

And

create procedure Create_Dummy2
(
    @Dummy_Variable1  int
)
as 

Select * From yourTable WHERE tableColumn = @Dummy_Variable1

And this is how you call it:

exec Create_Dummy1 1

Hope this helps.

like image 25
03Usr Avatar answered Oct 14 '22 06:10

03Usr