我有另一篇更详细代码的帖子,但我认为我的问题在于以下逻辑。是否可以有一个存储过程,调用另一个存储过程,并且被调用的过程返回一个要在第一个存储过程中使用的字符串?
例子:
ALTER PROCEDURE [dbo].[SP1]
-- Add the parameters for the stored procedure here
@output nvarchar(30)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
Declare @SP2Input nvarchar(30) = 'Input';
Declare @SP2Output nvarchar(30);
Execute @SP2Output = SP2 @SP2Input, @SP2Output;
If @SP2Output = 'Success'
Begin
Set @output = 'This worked';
End
Else
Begin
Set @output = 'This did not work';
End
Select @output;
结尾
这是下一个存储过程:
ALTER PROCEDURE [dbo].[SP2]
-- Add the parameters for the stored procedure here
@input nvarchar(30),
@output nvarchar(30) out
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
If @input = 'Input'
Begin
Set @output = 'Success';
End
Else
Begin
Set @output = 'Fail';
End
Select @output;
END
那么,调用存储过程 SP1 会返回什么?
Declare @output nvarchar(30);
Execute SP1 @output;
我会假设“这有效”会被退回?但是,返回两个结果:1)成功 2)这不起作用
我究竟做错了什么?