<ExecutionSequence>
<property name="Id">1437</property>
<property name="Name">seq</property>
<ExecutionBlock>
<property name="Name">Block1</property>
<ExecutionCommand>
<property name="Name">Cmd1</property>
</ExecutionCommand>
<ExecutionCommand>
<property name="Name">Cmd2</property>
</ExecutionCommand>
</ExecutionBlock>
<ExecutionBlock>
<property name="Name">Block2</property>
<ExecutionCommand>
<property name="Name">Cmd1</property>
</ExecutionCommand>
<ExecutionCommand>
<property name="Name">Cmd2</property>
</ExecutionCommand>
</ExecutionBlock>
</ExecutionSequence>
我希望所有的商品名称都带有各自的父名称
seq Block1 cmd1
seq Block1 cmd2
seq Block2 cmd1
seq Block2 cmd2
答案 0 :(得分:0)
select
e.c.value('(property[@name="Name"]/text())[1]', 'nvarchar(max)') as Sequence,
b.c.value('(property[@name="Name"]/text())[1]', 'nvarchar(max)') as Block,
c.c.value('(property[@name="Name"]/text())[1]', 'nvarchar(max)') as Command
from @data.nodes('ExecutionSequence') as e(c)
outer apply e.c.nodes('ExecutionBlock') as b(c)
outer apply b.c.nodes('ExecutionCommand') as c(c)
<强> sql fiddle demo 强>