开发者

SQL Server XML Extract Nodes

I am using SQL Server 2005 to Extract XML data. I would appreciate some help extracting the following XML snippet?

<ELEMENT_A>
    <CHILD_A _attribA="ABC">
       <CHILD_B Type="1">
          <CHILD_C>
             <CHILD_D Type="1" Date="2010-08-31">
                <CHILD_E _attribB="M0">
                   <CHILD_F>-0.32295</CHILD_F>
                </CHILD_E>
            </CHILD_D>
         </CHILD_C>
     </CHILD_B>
   </CHILD_A>
</ELEMENT_A>
开发者_JAVA百科

How do I get the data in the following tabular format? ELEMENT_A | _attribA | CHILD_A | CHILD_B | CHILD_C | CHILD_D | CHILD_E | CHILD_F

Note: I'd like to use select by nodes e.g. the following gets me the value of the first Attribute:

select v.value('@_attribA[1]','nvarchar(4)') from @doc.nodes('/ELEMENT_A/CHILD_A') x(v)

Very much appreciated, Thanks.


Hope this is not too late for you. I saw your question just today

select 
v.value('../../../../../@_attribA','nvarchar(4)')  as _attribA
,v.value('../../@Date','nvarchar(12)') as [Date]
,v.value('../@_attribB','nvarchar(2)') as _attribB
,v.value('.','float') as CHILD_F
,v.query('../../../../..') as CHILD_A

from @doc.nodes('/ELEMENT_A/CHILD_A/CHILD_B/CHILD_C/CHILD_D/CHILD_E/CHILD_F') x(v)
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜