I found this query here on KC which works great but its in Oracle can someone help changing this to MS SQL
SELECT d . rn "RowNum" , d . dataid "DataID" ,
LPAD ( '+' , lvl - 1 , '+' ) || ' ' || d . NAME "[+Hierarchy] Name" ,
d . path ,
DECODE ( d . subtype ,
0 , 'Folder' ,
1 , 'Shortcut' ,
2 , 'Generation' ,
130 , 'Topic' ,
131 , 'Category' ,
134 , 'Response' ,
136 , 'Compound doc' ,
138 , 'Release' ,
140 , 'URL' ,
144 , 'Document' ,
146 , 'Customview' ,
202 , 'Projet' ,
215 , 'Discussion' ,
258 , 'Request' ,
299 , 'LiveReport' ,
557 , 'E-mail composite' ,
751 , 'E-mail folder' ,
'Other' ) "Object type" ,
lvl - 1 "Level" ,
decode ( da . acltype , 1 , 'Owner' ,
2 , case when subtype = 202 THEN 'Coordonator'
when da . ownerid > 0 THEN 'Coordonator'
ELSE 'Owner Group' END ,
3 , 'Public' ,
0 , case when subtype = 202 and k . name = 'Members' THEN 'Members'
when subtype = 202 THEN 'Guest'
when da . ownerid > 0 and k . name = 'Members' THEN 'Members'
when da . ownerid > 0 THEN 'Guest'
ELSE 'Assigned' END ,
' ' ) "Access type" ,
coalesce ( case when kk . type = 0 then kk . firstname || ' ' || kk . lastname || ' (' || kk . name || ')'
else kk . name end ,
case when k . type = 0 then k . firstname || ' ' || k . lastname || ' (' || k . name || ')'
else k . name end ,
' ' ) "User/Group" ,
decode ( bitand ( da . PERMISSIONS , 2 ), 2 , 'See' , ' ' ) || ', ' ||
decode ( bitand ( da . PERMISSIONS , 36865 ), 36865 , 'SeeContent' , ' ' ) || ', ' ||
decode ( bitand ( da . PERMISSIONS , 65536 ), 65536 , 'Modif' , ' ' ) || ', ' ||
decode ( bitand ( da . PERMISSIONS , 131072 ), 131072 , 'ModifAttrib' , ' ' ) || ', ' ||
decode ( bitand ( da . PERMISSIONS , 4 ), 4 , 'Add' , ' ' ) || ', ' ||
decode ( bitand ( da . PERMISSIONS , 8192 ), 8192 , 'Reserve' , ' ' ) || ', ' ||
decode ( bitand ( da . PERMISSIONS , 16384 ), 16384 , 'DelVersions' , ' ' ) || ', ' ||
decode ( bitand ( da . PERMISSIONS , 8 ), 8 , 'Delete' , ' ' ) || ', ' ||
decode ( bitand ( da . PERMISSIONS , 16 ), 16 , 'ModifPerm' , ' ' ) "Rights"
FROM ( SELECT c . dataid , c . SUBTYPE , c . NAME ,
livelink . GETLLPATH ( d . ParentID ) as path ,
LEVEL lvl , ROWNUM AS rn
FROM dtree c
WHERE c . SUBTYPE IN ( 0 , 136 , 202 , 751 )
and level <= 99 CONNECT BY PRIOR c . dataid = ABS ( c . parentid )
START WITH c . dataid = 10587503 ) d
INNER JOIN dtreeacl da
ON da . dataid = d . dataid
left JOIN kuaf k
ON da . rightid = k . id
left join ( select * from kuafchildren
where exists
( select * from kuaf where name in ( 'Coordinators' , 'Members' , 'Guests' ) and kuaf . id = kuafchildren . id )
) kc
on k . id = kc . id
left JOIN kuaf kk
ON kc . childid = kk . id
where da . rightid <> - 2
and not (( d . subtype = 202 or da . ownerid > 0 ) and da . acltype = 1 )
and not exists
( select * from kuaf where name = 'Coordinators' and kuaf . id = kc . CHILDID )
and not( k . name = 'Guests' and kc . id is null and da . acltype <> 3 )
order by d . rn , decode ( da . acltype , 0 , 99 , da . acltype ), da . rightid