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