[英]xml node values with their respective parent node in sql
<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>
我想要所有的commnd名字和他们各自的父母名字
seq Block1 cmd1
seq Block1 cmd2
seq Block2 cmd1
seq Block2 cmd2
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.