A multi-statement table valued user-defined function looks like this: (example from Books Online)
CREATE FUNCTION dbo.FindReports (@InEmpID INTEGER)
RETURNS @retFindReports TABLE
(
EmployeeID int primary key NOT NULL,
FirstName nvarchar(255) NOT NULL,
LastName nvarchar(255) NOT NULL,
JobTitle nvarchar(50) NOT NULL,
RecursionLevel int NOT NULL
)
AS
BEGIN
INSERT INTO @retFindReports
SELECT EmployeeID, FirstName, LastName, JobTitle, RecursionLevel
FROM ....
RETURN
END;
The key things being the definition of the table variable and one or more inserts into that table variable
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability