0

是否可以从内联表值函数返回 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
)
4

1 回答 1

2

是的你可以。您只需将公用表表达式(您称为WITH语句)放在适当的位置:

create function TT()
RETURNS TABLE
AS
    RETURN (With Aardvark as (select * from sysobjects) --TODO - Remove *, use column names
        select * from Aardvark)
;
于 2013-07-05T07:18:17.810 回答