开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜