我正在尝试将以下Oracle查询转换为SQL Server,并且遇到了尝试为层次结构顺序创建CTE的问题。我只提供了最后一个select语句,因为有7个语句,并认为代码太长而无法发布。有任何想法吗?
SELECT '"'||rownum||'"' as ORIGINAL_ORDER, A.*
FROM (
SELECT
'"'||LEVEL||'"'
, CAST('"'||lpad(' ',level*2,' ')||P.POSITION_NBR||'"' AS VARCHAR(100)) AS
HIERARCHY
,'"'||P.POSITION_NBR||'"' AS POS_NBR
,'"'||P.DESCR||'"' AS POS_TITLE
,'"'||P.CLASSIFICATION_CD||'"' AS CLASSCd
, '"'||P.LOCATION||'"' AS LOC
, '"'||P.LOC_DESCR||'"' AS LOC_DESCR
, '"'||P.DEPTID||'"' AS DEP
, '"'||P.DEPT_DESCR||'"' AS DEP_DESCR
, F.LANG_PROF
, A.EMPS
, B.ACCOMPLISHMENT "ACC_READ"
, B.DT_ISSUED "DT_ISSUED_READ"
, B.RESULTS_LEVEL_CD "LEVEL_CD_READ"
, B.RESULTS_EXPIRY_DT "EXPIRY_DT_READ"
, C.ACCOMPLISHMENT "ACC_WRITE"
, C.DT_ISSUED "DT_ISSUED_WRITE"
, C.RESULTS_LEVEL_CD "LEVEL_CD_WRITE"
, C.RESULTS_EXPIRY_DT "EXPIRY_DT_WRITE"
, D.ACCOMPLISHMENT "ACC_ORAL"
, D.DT_ISSUED "DT_ISSUED_ORAL"
, D.RESULTS_LEVEL_CD "LEVEL_CD_ORAL"
, D.RESULTS_EXPIRY_DT "EXPIRY_DT_ORAL"
, E.XLATLONGNAME
from POSITIONS P
LEFT JOIN JOB A
ON P.POSITION_NBR = A.POSITION_NBR
LEFT JOIN SLE_READ B
ON A.EMPLID = B.EMPLID
LEFT JOIN SLE_WRITE C
ON A.EMPLID = C.EMPLID
LEFT JOIN SLE_ORAL D
ON A.EMPLID = D.EMPLID
LEFT JOIN POS_LANG_REQ E
ON A.POSITION_NBR = E.POSITION_NBR
LEFT JOIN POS_LANG_PROF F
ON P.POSITION_NBR = F.POSITION_NBR
start with P.position_nbr = '&&pPOSN_STARTSAT'`enter code here`
connect by nocycle prior p.position_nbr = p.reports_to
order siblings by p.position_nbr ) A