使用来自第一个存储过程的变量在另一个存储过程中调用一个存储过程

时间:2021-09-14 16:40:47

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

我有一个存储过程说@ Create_Dummy1正在传递一个变量。这在此存储过程中声明为@ Dummy_Variable1。

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

接下来,我需要从@ Create_Dummy1调用另一个存储过程@ Create_Dummy2。我需要在exec语句中传递@ Dummy_Variable1。

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

但是如果我尝试这样做,则只传递字符串@Dummy_Variable1而不是它所拥有的值。

2 个解决方案

#1


5  

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.

如果它仍然不起作用,您应该编辑您的问题以显示您的确切代码。

#2


3  

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.

希望这可以帮助。

#1


5  

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.

如果它仍然不起作用,您应该编辑您的问题以显示您的确切代码。

#2


3  

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.

希望这可以帮助。