Sql server对xml的使用

来源:互联网 发布:手机淘宝怎么合并付款 编辑:程序博客网 时间:2024/06/13 17:43

 

declare @data xml
 set @data='<bookstore>
  <book category="COOKING" >
     <title lang="en">Everyday Italian</title> 
     <author>Giada De Laurentiis</author> 
     <year>2005</year>
     <price>30.00</price>
   </book>
  <book category="CHILDREN"> 
      <title lang="jp">Harry Potter</title> 
      <author>J K. Rowling</author>
      <year>2005</year>
      <price>29.99</price>
  </book>
  <book category="WEB">
      <title lang="en">XQuery Kick Start</title>
       <author>James McGovern</author>
       <author>Per Bothner</author>
       <author>Kurt Cagle</author>
       <author>James Linn</author> 
       <author>Vaidyanathan Nagarajan</author>
        <year>2003</year>
       <price>49.99</price>
  </book>
  <book > 
           <title>Learning XML</title>
            <author>Erik T. Ray</author>
            <year>2003</year> 
            <price>39.95</price>
   </book>
   </bookstore>'

 

 

 

   --SELECT a.number as position,b.price
   --FROM
   --master.dbo.spt_values A CROSS APPLY
   --(SELECT C.value('price[1]','float') as  price
   --FROM @data.nodes('/bookstore/book[position()=sql:column("number")]')T(C)) b
 --  WHERE A.type='P'

 

 

SELECT  C.value('.','VARCHAR(200)') AS fjxm
                                FROM @data.nodes('/*/*/*') T(C)

原创粉丝点击