2014-06-22 79 views
2

如何獲取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語句返回一個錯誤: 消息2225,級別16,狀態1,行29 的XQuery [值()]:字符串文字預計

回答

1

你身邊需要雙引號「 ent「:

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