0

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">
<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
Graeme
  • 2,597
  • 8
  • 37
  • 50
  • I'v tried the query() method, but get one row with all values concatenated -: declare @xml xml set @xml = ' test1 test2 test3 test4 ' SELECT @xml.query('/myFields/field/text()') as test – Graeme Mar 17 '09 at 07:51

1 Answers1

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)
Lurker Indeed
  • 1,521
  • 1
  • 12
  • 21