当前位置: 代码迷 >> Sql Server >> 求救!获取XML根结点名称,该怎么处理
  详细解决方案

求救!获取XML根结点名称,该怎么处理

热度:28   发布时间:2016-04-27 20:22:08.0
求救!获取XML根结点名称
declare   @x   xml
set   @x   =  
' <Chicago>
    <Area> A1 </Area>
    <Group> 5 </Group>
    <Question> Q1 </Question>
</Chicago> '

如何使用SQL获得根结点的名称“Chicago”?

------解决方案--------------------
declare @x xml
set @x =
' <Chicago>
<Area> A1 </Area>
<Group> 5 </Group>
<Question> Q1 </Question>
</Chicago> '
SELECT @x.value( 'local-name(/*[1]) ', 'varchar(100) ')

-- 结果: Chicago
  相关解决方案