Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can i call Stored Procedure with in Function(UDF) in SQL SERVER vice versa ? if possible explain with small exp...
Posted

Yes we can call UDF in a SP but not the reverse.

Details:
If you know SP, we can write multiple queries in it. Calling a UDF is just like writing a Select query only. So instead of calling a table, you call UDF with parameters. Done!

If you know UDF's then you can make out that there is no way you can call SP in it.
 
Share this answer
 
When I try to execute a stored procedure from a function, I get: "Only functions and extended stored procedures can be executed from within a function." That might depend on the version of SQL Server though.

You can, however, call a function from a stored procedure:
SQL
CREATE FUNCTION dbo.fn_DoubleValue
(
    @val as int
)
RETURNS int
BEGIN
	RETURN @val * 2
END

GO

CREATE PROCEDURE ValueTimes4
	@val as int
AS
BEGIN
    SELECT dbo.fn_DoubleValue(dbo.fn_DoubleValue(@val))
END

GO

EXEC ValueTimes4 4
 
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