SQL语句-递归

WITH UserID (OrgCode, ParentCode, Level)
AS
(

SELECT OrgCode,ParentCode,0 AS Level
FROM UMS_Organization
WHERE OrgCode= 'ORG12743'
UNION ALL
SELECT e.OrgCode,e.ParentCode, Level + 1
FROM UMS_Organization AS e
INNER JOIN UserID AS d
ON e.ParentCode = d.OrgCode
)
SELECT OrgCode FROM UserID

 

 

http://www.cnblogs.com/xqhppt/archive/2011/02/15/1955366.html

posted @ 2015-06-23 16:56  CTRA王大大  阅读(236)  评论(0编辑  收藏  举报