Question : calling stored procedure from function generates error

I have the following function:

CREATE FUNCTION dbo.test1 ()  
RETURNS  Int  AS  
BEGIN

exec test

return 3
END


The stored procedure test is as follows

select    *
From Customers
WHERE     (CustomerID = 'ALFKI')

and running the function produces the following error:

Server: Msg 557, Level 16, State 2, Procedure test, Line 5
Only functions and extended stored procedures can be executed from within a function.

Since test does not modify anything, why is this error message generated?

Answer : calling stored procedure from function generates error

That doesn't matter. Check the syntax (including the notes about limitations) of the stored functions which clearly states (the same as your error message) that you cannot use stored procedures inside of UDF.

Random Solutions  
 
programming4us programming4us