ALTER FUNCTION UFun_GetChildren(@ID nvarchar(60))
RETURNS @tbChildren TABLE (ID varchar(60) )
AS
BEGIN
WITH UFun_GetChildren(ID)
AS
(
SELECT OrganizationID FROM ECOrganization WHERE ParentOrganizationID=@ID
UNION ALL
SELECT OrganizationID FROM ECOrganization
INNER JOIN UFun_GetChildren
ON UFun_GetChildren.id = ECOrganization.ParentOrganizationID
)
INSERT INTO @tbChildren SELECT Id FROM UFun_GetChildren
RETURN
END
GO
参考
http://www.cnblogs.com/kenshincui/archive/2011/12/30/2308082.html