我有以下简单的XML片段。如果我想提取'EntityFriendlyName'属性,T-SQL会是什么样子?
<SimpleRuleValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<EntityId>0</EntityId>
<EntityFriendlyName>ALine</EntityFriendlyName>
</SimpleRuleValue>
答案 0 :(得分:3)
这将是这样的:
SELECT CAST(X.SomeXML AS XML).value('(SimpleRuleValue/EntityFriendlyName)[1]','nvarchar(1000)') AS EntityFriendlyName
FROM XmlSource X
答案 1 :(得分:0)
这是一种方式:
declare @x xml
set @x = '<SimpleRuleValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<EntityId>0</EntityId>
<EntityFriendlyName>ALine</EntityFriendlyName>
</SimpleRuleValue>'
select @x.query('data(SimpleRuleValue/EntityFriendlyName)')