Returning table-type by function
Can user-defined table-valued (or any other function) return table-type in SQL Server 2008开发者_开发问答?
At present, it does not seem to be possible to return a UDTT from a UDF. A UDF can return a table variable, or an inline table.
Returning an inline table:
CREATE FUNCTION dbo.MyFunc1
RETURNS TABLE
AS RETURN
SELECT <columns>
FROM <table>
WHERE <conditions>
Returning a table variable:
CREATE FUNCTION dbo.MyFunc2
RETURNS @Tbl TABLE
(
ID int,
Name varchar(50)
)
AS BEGIN
INSERT @Tbl (ID, Name)
SELECT ID, Name
FROM <table>
WHERE <conditions>
RETURN
END
Those are the only types of TVFs at the moment.
精彩评论