可能重复:
Simulation of CONNECT BY PRIOR of ORACLE in SQL SERVER
- 我需要将下面的PL / SQL转换为SQL
SELECT DataMapId, REPLACE((QtyType, '#'), '#') AS QtyTypes
FROM (
SELECT DataMapId, '<QtyType>' + cast(DataTypeId as nvarchar(200)) + '</QtyType>' AS QtyType,
ROW_NUMBER() OVER (PARTITION BY DataMapId ORDER BY DataTypeId) AS rn
FROM tblDataMapChannels
)
WHERE CONNECT_BY_ISLEAF = 1
CONNECT BY rn = PRIOR rn + 1
AND DataMapId = PRIOR DataMapId
START WITH rn = 1