[SQL] syntaxhighlighter_viewsource syntaxhighlighter_copycode
BEGIN
WITH CTE AS(
SELECT ID,depNum,depName,depOwnerName,depName as UpDepName FROM t_b_Department WHERE ParentDepId=0
UNION ALL
SELECT b.ID,b.depNum,b.depName,b.depOwnerName,p.depName as UpDepName FROM CTE p INNER JOIN t_b_Department b ON p.ID=b.ParentDepId
)
SELECT depNum,depName,depOwnerName,UpDepName FROM CTE
END
[SQL] syntaxhighlighter_viewsource syntaxhighlighter_copycode
WITH CTE AS
(
SELECT ID,depNum,depName,depOwnerName,depName as UpDepName FROM t_b_Department WHERE ParentDepId=79 AND ID=70
UNION ALL
SELECT b.ID,b.depNum,b.depName,b.depOwnerName,p.depName as UpDepName FROM CTE p INNER JOIN t_b_Department b ON p.ID=b.ParentDepId
)
SELECT ID,depNum,depName,depOwnerName,UpDepName FROM CTE