如何在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()]:预期字符串文字
答案 0 :(得分:1)
你需要双引号&#34; ent&#34;:
SELECT x.xml.value('data(processing-instruction("ent")[1])','varchar(30)')
FROM @x.nodes('/root/entity') x(xml);