我在存储在 SQL Server 2008 中的表中有一个列,其中包含一些文档的完整路径。
我需要将路径转换为父子层次结构,如下所示。我需要这种结构,因为它是我使用它的第三方软件所必需的。
这是如何做到最优雅的?
从:
root/Dir1/Dir11/Dir3/Docname1.txt
root/Dir1/Dir12/Dir3/Docname2.txt
root/Dir1/Dir11/Docname3.txt
root/Dir1/Dir11/Dir31/Docname4.txt
至:
[Value] [Parent]
Docname1.txt root/Dir1/Dir11/Dir3
root/Dir1/Dir11/Dir3 root/Dir1/Dir11
root/Dir1/Dir11 root/Dir1
root/Dir1 root
Docname2.txt root/Dir1/Dir12/Dir3
root/Dir1/Dir12/Dir3 root/Dir1/Dir12
root/Dir1/Dir12 root/Dir1
root/Dir1 root
Docname3.txt root/Dir1/Dir11
root/Dir1/Dir11 root/Dir1
root/Dir1 root
Docname4.txt root/Dir1/Dir11/Dir31
root/Dir1/Dir11/Dir31 root/Dir1/Dir11
root/Dir1/Dir11 root/Dir1
root/Dir1 root