How to invoke another stored procedure in a stored procedure

Source: Internet
Author: User
Tags numeric value

To invoke another stored procedure in one of the stored procedures, you can invoke one of the following two ways:

EXECUTE <欲执行之预存程序的名称>

Or

EXEC <欲执行之预存程序的名称>

If the name of the stored procedure being invoked has a return value, and you need to receive the return value, you must use the OUTPUT keyword to enable the invoked stored procedure to take back the value when executing the stored procedure you want to execute. Only you must first use the OUTPUT keyword to create the data type of the numeric value to be returned in the invoked stored procedure. As shown below, this is an example:

CREATE PROCEDURE #欢迎 @strInput NVARCHAR(50) OUTPUT
AS
 BEGIN
  SET @strInput = @strInput + '欢迎来到:台北面摊—章立民研究室';
 END;
GO
CREATE PROCEDURE #您好
AS
 BEGIN
  DECLARE @strHi NVARCHAR(50);
  SET @strHi = '嗨!您好!';
  EXECUTE #欢迎 @strHi OUTPUT;
  PRINT @strHi;
 END
GO

--now to test whether the stored procedure "#您好" can be executed correctly

--we use three ways to test

PRINT '使用 EXECUTE 陈述式来测试';
EXECUTE #您好;
PRINT '';
GO

PRINT '使用 EXEC 陈述式来测试';
EXEC #您好;
PRINT '';
GO

PRINT '直接使用 Stored Procedure 名称来测试看看';
GO
#您好;
GO

Please note:

The stored procedures established by this example are temporary, and are automatically removed when you use an online and SQL Server instance that is interrupted.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.