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
posted on 2012-08-03 17:26  万德源  阅读(1715)  评论(0编辑  收藏  举报