且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从 t-sql 中的 xml 变量中获取节点名称和值

更新时间:2023-02-05 20:31:36

您可以使用 local-name() 函数来获取 XML 节点的名称 - 尝试如下操作:>

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: