SQL Server only functions and extended stored procedures can be executed from within a function

Source: Internet
Author: User

A custom stored procedure is called in a SQL Server custom function, and after executing this function, the following prompt is issued: "Only functions and extended stored procedures can be executed from within the function."
Reason: The function can only use simple SQL statements, logical control statements, complicated stored procedures can not be called, in the function can not use execute sp_executesql or execute. The workaround changes the function to a stored procedure and then uses the stored procedure in another stored procedure as if it were called a function.
The following is a stored procedure that invokes an instance of another stored procedure, with parameters passed.
--Stored Procedure Sp_b
Create proc Sp_b
@A int,
@B int,
@c int Output
As

Set @c = @A + @B
Go

--Stored Procedure p_a
Create proc Sp_a
@A int,
@B int
As
DECLARE @c int
exec sp_b @A, @B, @c output
Print @c
Go
--Test
EXEC sp_a 3, 5

SQL Server only functions and extended stored procedures can be executed from within a function

Related Article

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.