开发者

Returning table-type by function

开发者 https://www.devze.com 2022-12-20 14:48 出处:网络
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 tab

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

精彩评论

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

关注公众号