WITH Tree(DEPTCODE, PARENTCODE,DEPTNAME,DEPT_TYPE_CODE,DEPT_TYPE_NAME) AS
(SELECT DEPTCODE ,PARENTCODE,DEPTNAME,DEPT_TYPE_CODE,DEPT_TYPE_NAME
FROM TB_AUT_DEPARTMENT P
WHERE P.DEPTCODE = 'DEPT000004'
UNION ALL
SELECT C.DEPTCODE ,C.PARENTCODE,C.DEPTNAME,C.DEPT_TYPE_CODE,C.DEPT_TYPE_NAME
FROM TB_AUT_DEPARTMENT C
INNER JOIN Tree T ON T.DEPTCODE = C.PARENTCODE
)
SELECT *
FROM Tree WHERE 1=1
ORDER BY DEPTCODE
-------------------------------------------------------------