2
<value1>

<name>
 <account id="4567890" firstname="abc">
</account>
</name> 

</value1>

我需要在 xml 中的帐户标签中取出 id

SELECT 
       T.id
     , T.request_xml.value(
          '(Value1/name/account/id)[1]', 
          'varchar(50)'
       ) AS id
FROM [table] AS T
4

1 回答 1

1

尝试使用@ -

DECLARE @XML XML
SELECT @XML = '
<value1>
<name>
 <account id="4567890" firstname="abc">
</account>
</name> 
</value1>'

SELECT id = @XML.value('(value1/name/account/@id)[1]', 'VARCHAR(50)') 

您的查询 -

SELECT 
       T.id
     , T.request_xml.value(
          '(Value1/name/account/@id)[1]', --<-- @
          'varchar(50)'
       ) AS id
FROM [table] AS T
于 2013-07-29T10:50:19.757 回答