1

我有一系列使用相同变量的存储过程。我希望每个存储过程在移动到下一个之前完全执行。我在每个过程的末尾添加了一个 GO 语句,但我不想在每次运行后重新声明变量。有没有办法在 GO 之后循环回变量,然后在序列中选择下一个 proc?下面是一个供参考的代码示例:

DECLARE @depType AS VARCHAR(20)
SET @deptype='X'

EXEC [Stored_Procedure1], @deptype
GO

EXEC [Stored_Procedure2], @deptype
GO

EXEC [Stored_Procedure3], @deptype
GO
4

2 回答 2

2

只需省略GO声明:

DECLARE @depType AS VARCHAR(20);
SET @deptype='X';

EXEC [Stored_Procedure1], @deptype;

EXEC [Stored_Procedure2], @deptype;

EXEC [Stored_Procedure3], @deptype;

它们定义了一个批次,而变量仅在一个批次中定义。

于 2013-06-05T15:13:36.737 回答
0

会做

GO TO; -- Stored_Procedure1 EXEC [Stored_Procedure1], @deptype;

有帮助吗?

于 2013-06-21T05:51:56.057 回答