0
<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>

我想要所有命令名称及其各自的父名称

序列块1 cmd1

序列块1 cmd2

seq Block2 cmd1

seq Block2 cmd2

4

1 回答 1

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

于 2013-10-03T17:18:14.010 回答