从外部存储过程中获取参数值 - 嵌套存储过程

时间:2014-10-30 13:50:59

标签: stored-procedures

我有这个存储过程。我想知道是否可以获取来自外部存储过程的参数的值并将其传递给内部存储过程。以下是我的存储过程。

CREATE PROCEDURE [dbo].[OuterStoredProcedure] 
@OuterParameter_FirstName VARCHAR(50),
@InnerParameter_Spouse_FirstName VARCHAR(50)

AS BEGIN

DECLARE @DT DATETIME
SET @DT = GETDATE()

INSERT EMPLOYEE_DETAILS WITH (ROWLOCK)
(
    FirstName
)

VALUES
(
    @OuterParameter_FirstName
)

DECLARE @STOREPROC_QUERY NVARCHAR(MAX)
SET @STOREPROC_QUERY = 'CREATE PROCEDURE InnerStoredProcedure
                        AS
                        BEGIN
                            DECLARE @DT DATETIME
                            SET @DT = GETDATE()

                            INSERT EMPLOYEE_SPOUSE WITH(ROWLOCK)
                            (
                                Spouse_FirstName
                            )

                            VALUES
                            (
                                ''HOW WOULD I BE ABLE TO PASS THE VALUE OF THE PARAMETER @InnerParameter_Spouse_FirstName INSIDE THIS SECTION''
                            )
                        END'

EXEC(@STOREPROC_QUERY)

END

1 个答案:

答案 0 :(得分:0)

''' + @ InnerParameter_Spouse_FirstName +'''

在为第二个存储过程调用SET命令时,所需的参数仍在范围内。它应该仍然能够获得价值。