开发者

Getting the data of Ancestor node + XQuery-Sql

This is how my XML looks like :

 <Product sequence_number="1" number="1543448904" id="S1" unit_number="1">

     <consumer_narrative name="GLENN,GREGORY" date_filed="02/13/2009">
        <message type="Consumer Comments">THE CONSUMER STATES THIS WAS  NOT </message>
        <message type="Consumer Comments">THE PRODUCT REQUESTED.</message>
     </consumer_narrative></Product> <Product sequence_number="2" number="1543448905" id="S1" unit_number="1">

     <consumer_narrative name="JOHN,GORDON" date_filed="08/23/2009">
        <message type="Con开发者_运维技巧sumer Comments">THE CONSUMER STATES THAT</message>
        <message type="Consumer Comments">WRONG PRODUCT WAS SENT.</message>
     </consumer_narrative>  </Product>

My Query :

SELECT 

    tab.col.value('../@number', 'varchar(30)')   [Claim Number], 
    tab.col.value('../@name', 'varchar(30)')   [Name], 
    tab.col.value('../@date_filed', 'varchar(30)')   [DateField],
    tab.col.value('@type', 'varchar(50)')   [Type], 
    tab.col.value('.', 'varchar(250)')   [CustomerComments]

FROM XMLTABLE AS B
CROSS APPLY xmldocument.nodes('//Product/consumer_narrative/message') tab(col)
WHERE B.XMLId = 123

Gives me "null" for Claim Number. What should I have in the place of ../@number to get the claim number.


Another "../"

The first ../ has only taken you upto the consumer_narrative element

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜