As I remember you cannot use EXEC() in UDF.
...
> Welcome.
> This is my first post in this group. I have a problem. I tried to
> create a table-valued function that returns
> a table as a result of execution stored procedure. Procedure
> dbo.uspGetEmployeeManagers is available in AdwentureWorks database. I
> have created such thing linke below, but it doesn't work. Can anyone
> help me?
> PS: Sorry for my english. I still learn it.
> CREATE FUNCTION dbo.GetStoredProcedureResult
> (
> @employeeID int
> )
> RETURNS @temp TABLE(
> recursion int,
> empID int,
> name varchar(256),
> surname varchar(256),
> managerID int,
> managerName varchar(256),
> managerSurname varchar(256)
> )
> BEGIN
> INSERT INTO @temp(recursion, empID, name, surname, managerID,
> managerName,managerSurname)
> VALUES(EXEC dbo.uspGetEmployeeManagers 1)
> RETURN
> END
> GO