SQL Server xml 列には、次のような xml があります。
<Test>
<Operations>
<Operations type="OperationSend">
<OperationSend>
<ToCompanyId>1</ToCompanyId>
<Date>2011-05-01T00:00:00</Date>
</OperationSend>
</Operations>
<Operations type="OperationSell">
<OperationSell>
<ToCompanyId>33</ToCompanyId>
<Amount>12</Amount>
</OperationSell>
</Operations>
<Operations type="OperationEdit">
<OperationEdit>
<ToCompanyId>12</ToCompanyId>
<Date>2011-11-01T00:00:00</Date>
</OperationEdit>
</Operations>
</Operations>
</Test>
最後の操作 (12) から ToCompanyId を取得する必要があります。私はこのようなものに来ました。何を入れるべきですか??? ToCompanyId で任意の操作タイプが存在する可能性がある場合。
select testxml.query('(/Test/Operations/Operations)[last()]/???/ToCompanyId') from dbo.MyXmlTable