Return 存储过程的多个输出

Return multiple output from a stored procedure

可以使用

将多个输出值 return 输出到父存储过程

exec 'stored procedure name' 'inputval','outval1','outval2'

exec sp_SubSalaryCalcuation @sec1_in,@sec1_out,@worktimefrm,@worktimeto,@out_timestatus OUTPUT,@out_status OUTPUT,@out_overtime OUTPUT

我需要调用这个存储过程

ALTER PROCEDURE [dbo].[sp_SubSalaryCalcuation] 
@out_overtime nvarchar(100) OUTPUT,
@out_status nvarchar(100) OUTPUT,
@out_overtimestatus nvarchar(100) OUTPUT,
@sec1_in nvarchar(200),
@sec1_out nvarchar(200),
AS
BEGIN
SET @out_status=@sec1_in
SET @out_overtime=0
SET @out_overtimestatus=0

END

是的。你可以这样做。您可以从另一个过程获取多个输出参数到父过程。考虑以下示例。

Note : You should pass the parameters in the same order that is present in sp_SubSalaryCalcuation procedure.

1.家长程序

CREATE PROCEDURE ParentProcedure

    @Param1 nvarchar(30)

AS
BEGIN

    DECLARE @out_timestatus nvarchar(100)
    DECLARE @out_status nvarchar(100)
    DECLARE @out_overtime nvarchar(100)

    SET NOCOUNT ON;

    -- Send parameters in the same order of sp_SubSalaryCalcuation
    exec sp_SubSalaryCalcuation 1,2,3,4,@out_timestatus OUTPUT,@out_status OUTPUT,@out_overtime OUTPUT

    PRINT @out_timestatus
    PRINT @out_status
    PRINT @out_overtime

END
GO

2。子过程

CREATE PROCEDURE sp_SubSalaryCalcuation 
@sec1_in nvarchar(200),
@sec1_out nvarchar(200),
@worktimefrm nvarchar(200),
@worktimeto nvarchar(200),
@out_overtime nvarchar(100) OUTPUT,
@out_status nvarchar(100) OUTPUT,
@out_overtimestatus nvarchar(100) OUTPUT

AS
BEGIN

    SET NOCOUNT ON;

    SET @out_overtime = 10
    SET @out_status = 20
    SET @out_overtimestatus = 30

END
GO

parent procedure的参数结果如下

x-----------------x----------x
|     Variable    |   Value  |
x-----------------x----------x
| @out_timestatus |   10     |
| @out_status     |   20     |
| @out_overtime   |   30     |
x-----------------x----------x