获取处理指令值

时间:2014-06-22 02:17:54

标签: sql-server xml

如何在SQL Server中获取处理指令标记的值?

declare @x XML = 
'<root>
  <entity>
    <?ent LOOKUPS?>
  </entity>
  <entity>
    <?ent STAFF?>
  </entity>
  <entity>
    <?ent SIR?>
  </entity>
</root>';

SELECT x.xml.value('processing-instruction(ent)[1]','varchar(30)')
FROM @x.nodes('/root/entity') x(xml);

select语句返回错误: Msg 2225,Level 16,State 1,Line 29 XQuery [value()]:预期字符串文字

1 个答案:

答案 0 :(得分:1)

你需要双引号&#34; ent&#34;:

SELECT x.xml.value('data(processing-instruction("ent")[1])','varchar(30)')
FROM @x.nodes('/root/entity') x(xml);