sql query xml values returning NULL

后端 未结 2 1645
Happy的楠姐
Happy的楠姐 2021-01-19 10:09

I\'m not experienced with the xml structure and need a start-point to how I can retrieve the values from xml structure below.

I fetch the <

2条回答
  •  爱一瞬间的悲伤
    2021-01-19 10:49

    You must set namespace for xml before get value

    DECLARE @xml XML = N'
      
        
          ENGI.PA
          13.53
          5/23/2017
          
          +0.06
          13.45
          13.59
          13.40
          1524437
          32.95B
          13.47
          +0.48%
          10.77 - 15.20
          -0.23
          N/A
          ENGIE
        
      
    '
    
    ;WITH XMLNAMESPACES('http://www.webserviceX.NET/' as ns)
    SELECT 
    x.s.value('(./ns:Symbol)[1]', 'varchar(50)') AS [Symbol]
    FROM @xml.nodes('/ns:string/ns:StockQuotes/ns:Stock') AS x(s);
    

    Returns

    Symbol
    --------
    ENGI.PA
    

提交回复
热议问题