<value1>
<name>
<account id="4567890" firstname="abc">
</account>
</name>
</value1>
我需要在xml
中的帐户标记中取出idSELECT
T.id
, T.request_xml.value(
'(Value1/name/account/id)[1]',
'varchar(50)'
) AS id
FROM [table] AS T
答案 0 :(得分: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