Return rows from XQuery

Hello,
running the following code:

declare @x xml
set @x='<ManuInstructions ProductModelID="1" ProductModelName="SomeBike" >
<Location LocationID="L1" LocationName="Name 1" />
<Location LocationID="L2" LocationName="Name 2" />
</ManuInstructions>'
SELECT @x.query('
for $location in /ManuInstructions/Location
return data($location/@LocationID)
') as LocationID

I get the following result:

LocationID
-
L1 L2
(1 row(s) affected)

How can I get two rows instead ?, ie.:

LocationID
-
L1
L2
(2 row(s) affected)

Thanks,
Pierre

[766 byte] By [pierreg] at [2008-2-15]
# 1
You can use the .nodes() method:

declare @x xml

set @x='<ManuInstructions ProductModelID="1" ProductModelName="SomeBike" >

<Location LocationID="L1" LocationName="Name 1" />

<Location LocationID="L2" LocationName="Name 2" />

</ManuInstructions>'

SELECT node.ref.value('@LocationID', 'varchar(2)') as LocationID

from @x.nodes('/ManuInstructions/Location') node(ref)

JohnGallardo-MSFT at 2007-9-8 > top of Msdn Tech,SQL Server,SQL Server XML...

SQL Server

Site Classified