Click here to Skip to main content
15,896,296 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
can we call a stored procedure in a function?
If yes, how to do it?

[EDIT - OP code from comment]
SQL
CREATE PROCEDURE USP_TEST
AS
BEGIN
	PRINT 1
END

CREATE FUNCTION TEST_1() 
RETURNS INT
bEGIN
	DECLARE @C INT
	EXEC USP_TEST
	RETURN @C
END

SELECT DBO.Test_1()
Posted
Updated 23-Nov-13 4:48am
v2
Comments
thatraja 23-Nov-13 9:09am    
why do you want that?
anilrepala505 23-Nov-13 9:46am    
i have a sp and i want to call in function
anilrepala505 23-Nov-13 9:46am    
CREATE PROCEDURE USP_TEST
AS
BEGIN
PRINT 1
END


CREATE FUNCTION TEST_1()
RETURNS INT
bEGIN
DECLARE @C INT
EXEC USP_TEST
RETURN @C
END

SELECT DBO.Test_1()
CHill60 23-Nov-13 10:49am    
What happened when you tried it?
anilrepala505 23-Nov-13 10:55am    
Msg 557, Level 16, State 2, Line 1
Only functions and some extended stored procedures can be executed from within a function.

1 solution

Well the error message is quite clear ... you can't do that.
http://www.unglesbee.com/wordpress/msg-557-sql-server-error-messages/[^]

See if you can replace your stored procedure with a function, or convert your function into a stored procedure
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900