在SQL Server中解析XML

时间:2015-04-27 10:28:49

标签: sql sql-server xml

<ROOT>
    <arn>arn001</arn>
    <arn>arn002</arn>
</ROOT>

尝试以下代码

SELECT
ARN.value('(//arn/text())[1]','VARCHAR(100)') AS arns --TAG
FROM
@xml.nodes('/ROOT')AS TEMPTABLE(ARN)

仅返回第一个值

1 个答案:

答案 0 :(得分:1)

尝试这种方式:

declare @xml xml = '<ROOT>
        <arn>arn001</arn>
        <arn>arn002</arn>
    </ROOT>'

SELECT
X.value('.','VARCHAR(100)') AS arns 
FROM
@xml.nodes('/ROOT/arn')AS T(X)

<强> SQL Fiddle