views:

222

answers:

1

I can get the first record back from the code below in SQL Server 2005. How do I get them all? If I remove the '[1]' index I get some singleton error...

declare @xml xml
set @xml = 
'<my:myFields xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-03-16T20:13:11"&gt;
<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
A: 
declare @xml xml
set @xml = 
'<my:myFields xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-03-16T20:13:11"&gt;
<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)
Lurker Indeed