How to get node name and values from an xml variable in t-sql

后端 未结 1 454
走了就别回头了
走了就别回头了 2020-12-15 09:03

I have the following xml -



        
相关标签:
1条回答
  • 2020-12-15 09:43

    You can use the local-name() function to the get name of the XML node - try something like this:

    DECLARE @input XML =  '...your xml here.....'
    
    SELECT
        NodeName = C.value('local-name(.)', 'varchar(50)'),
        NodeValue = C.value('(.)[1]', 'varchar(50)') 
    FROM @input.nodes('/Surveys/Svy/*') AS T(C)
    

    This should give you an output something like:

    enter image description here

    0 讨论(0)
提交回复
热议问题