从XQuery和SQL Server 2005获取行集

时间:2009-03-16 21:48:03

标签: sql-server-2005 xquery

我可以从SQL Server 2005中的代码中获取第一条记录。如何获取所有这些记录?如果我删除'[1]'索引,我会得到一些单例错误......

declare @xml xml
set @xml = 
'<my:myFields xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-03-16T20:13:11">
<my:field>test1</my:field>
<my:field>test2</my:field>
<my:field>test3</my:field>
<my:field>test4</my:field>
</my:myFields>'
SELECT @xml.value('declare namespace     my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-03-16T20:13:11";         
(/my:myFields/my:field)[1]', 'varchar(100)') as test

1 个答案:

答案 0 :(得分:0)

declare @xml xml
set @xml = 
'<my:myFields xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-03-16T20:13:11">
<my:field>test1</my:field>
<my:field>test2</my:field>
<my:field>test3</my:field>
<my:field>test4</my:field>
</my:myFields>'

SELECT Y.ID.value('.', 'varchar(100)') as test
FROM @xml.nodes('declare namespace my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-03-16T20:13:11"; 
                (/my:myFields/my:field)') as Y(ID)