从Xml获取记录

时间:2011-11-04 09:47:35

标签: sql-server-2008

这是我的XML:

DECLARE @ChargeDetail xml

SET @ChargeDetail ='
    <Amount>
       <First>
          <Second>1</Second>
          <Second>2</Second>
       </First>
    </Amount>'

我正在使用此查询:

SELECT tc.value('Second[1]','varchar(max)') as ID 
FROM @ChargeDetail.nodes('/Amount/First') as tb(tc)

我希望输出为:

ID
1
2

但此查询仅返回1

请帮助我....

提前致谢。

2 个答案:

答案 0 :(得分:3)

select T.X.value('.', 'varchar(max)') as ID
from @ChargeDetail.nodes('/Amount/First/Second') as T(X)

答案 1 :(得分:2)

SELECT tb.tc.value('.','varchar(max)') as ID 
FROM    @ChargeDetail.nodes('//Amount/First/Second') as tb(tc)