查询树节点下的所有子节点包括根节点
DECLARE @ID UNIQUEIDENTIFIER='3ECB95B8-CB41-4657-8D65-FAC9AB3ED82E'
;with MyCTE(ID,[USER_NAME]) as
(
select ID,[USER_NAME]
from USERS where CREATED_BY=@ID
union all
select e.ID,e.[USER_NAME]
from USERS as e,MyCTE as c where e.CREATED_BY = c.ID
)
select ID,[USER_NAME]
FROM USERS where ID=@ID
UNION ALL
select ID,[USER_NAME] from MyCTE