【发布时间】:2019-05-20 00:52:56
【问题描述】:
我有以下需要查询的 xml:
declare @xml xml = '<root>
<level1>
<property1>Value1</property1>
<property2>Value2</property2>
<level2List>
<level2>Child1</level2>
<level2>Child2</level2>
</level2List>
</level1>
<level1>
<property1>Value3</property1>
<property2>Value4</property2>
<level2List>
<level2>Child3</level2>
<level2>Child4</level2>
</level2List>
</level1>
</root>'
我需要以下结果:
Property1 Property2 Child
Value1 Value2 Child1
Value1 Value2 Child2
Value3 Value4 Child3
Value3 Value4 Child4
我有这个问题:
select col.value('Property1','varchar(100)') Property1,
col.value('Property2','varchar(100)') Property2
from @xml.nodes('//root/level1') as tab(col)
但我不知道如何将父节点与其子节点连接起来。有什么想法吗?
【问题讨论】:
-
我不认为你的 XML 是这样格式化的。根据本例,
level2List、Property1、property2是Level节点下的姐妹节点。
标签: sql sql-server xml tsql sql-server-2016