Calling one stored procedure in another stored procedure using variables from the first stored procedure

I have a stored procedure say @Create_Dummy1 that is passed to 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 will only be passed in place of the value it has.

+6
source share
2 answers

I execute procedures inside other procedures, such as:

 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 

If it still does not work, you should change your question to show your exact code.

+5
source

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 here is what you call it:

 exec Create_Dummy1 1 

Hope this helps.

+3
source

Source: https://habr.com/ru/post/927432/


All Articles