Get the names of attributes from an element in a SQL XML column

后端 未结 4 681
-上瘾入骨i
-上瘾入骨i 2021-02-06 10:36

For this xml (in a SQL 2005 XML column):


 1
 
 

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-06 10:48

    DECLARE @xml as xml
    
    SET @xml = 
    '
     1
     
     
    '
    
    SELECT DISTINCT
     CAST(Attribute.Name.query('local-name(.)') AS VARCHAR(100)) Attribute,
     Attribute.Name.value('.','VARCHAR(100)') Value
    FROM @xml.nodes('//@*') Attribute(Name)
    

    Returns:

    Attribute Value

    ba 1

    bb 2

    bc 3

    bd 3

提交回复
热议问题