ITVF可以使用With-Statement吗?

时间:2013-07-05 07:05:00

标签: sql tsql sql-server-2012

是否可以从内联表值函数返回With-Statement表?

我的With-Statement看起来像这样

WITH ret AS(
        SELECT  t.ID
        FROM    SelfReferencingTable
        WHERE   ID = @PartnerID
        UNION ALL
        SELECT  t.ID
        FROM    (SelfReferencingTable) t INNER JOIN
                ret r ON t.ParentID = r.ID
)

1 个答案:

答案 0 :(得分:2)

是的,你可以。您只需将common table expression(您所指的WITH语句)放在适当的位置:

create function TT()
RETURNS TABLE
AS
    RETURN (With Aardvark as (select * from sysobjects) --TODO - Remove *, use column names
        select * from Aardvark)
;