XQuery returns one row where XML item has many occurrences. (SQL Server 2005)

folks:

I'm trying to learn SQL server 2005 XML support.  As an academic exercise, I put together the below script.  Everything is working fine except when i do my xquery.  What I'm getting back is one row containing a concatination of the strings I'm trying to query out.  Specifically, I get:
Item
-----------------------------
Tricycle Wicker Basket

(1 row(s) affected)

where I want
-----------------------------
Tricycle
Wicker Basket

(2 row(s) affected)

The XML I'm querying against is:
<Sale>
<EmployeeID>2</EmployeeID>
<LineItems>
<LineItem><Item>Tricycle</Item><Cost>28.65</Cost></LineItem>
<LineItem><Item>Wicker Basket</Item><Cost>1.65</Cost></LineItem>
</LineItems>
</Sale>
This is stored in an XML datatype column "Contract" in the "Sale" table.

The xquery statement is:
select contract.query('for $var in data(/Sale/LineItems/LineItem/Item) return string($var)') as Item
    from Sale
    where EmployeeID = 2

I appreciate any advice you can give me.




If it helps - the entire script is:
CREATE TABLE Employee
      (
           EmployeeID int identity(1,1) NOT NULL primary key,
           EmployeeName varchar(50) NOT NULL
      )
GO

CREATE TABLE Sale
    (
         SaleID int identity(1,1) not null primary key,
         EmployeeID int not null,
         StoreId int not null,
         Contract xml not null
     )
go
ALTER TABLE Sale ADD CONSTRAINT
      FK_Sale_Employee FOREIGN KEY
      (
          EmployeeID
      )
    REFERENCES Employee
      (
          EmployeeID
      )
GO


insert into Employee (EmployeeName)
   values('John')
go
insert into Employee (EmployeeName)
   values('Rich')
go

insert into Sale (EmployeeID, StoreID, Contract)
   values (1, 2, '<Sale><EmployeeID>1</EmployeeID><LineItems><LineItem><Item>Boat</Item><Cost>4268.65</Cost></LineItem><LineItem><Item>Space Shuttle</Item><Cost>4523745341.65</Cost></LineItem></LineItems></Sale>')
insert into Sale (EmployeeID, StoreID, Contract)
   values (1, 2, '<Sale><EmployeeID>1</EmployeeID><LineItems><LineItem><Item>Plain</Item><Cost>44268.65</Cost></LineItem><LineItem><Item>Train</Item><Cost>745341.65</Cost></LineItem></LineItems></Sale>')
insert into Sale (EmployeeID, StoreID, Contract)
   values (2, 2, '<Sale><EmployeeID>2</EmployeeID><LineItems><LineItem><Item>Tricycle</Item><Cost>28.65</Cost></LineItem><LineItem><Item>Wicker Basket</Item><Cost>1.65</Cost></LineItem></LineItems></Sale>')

select contract.query('for $var in data(/Sale/LineItems/LineItem/Item) return string($var)') as Item
    from Sale
    where EmployeeID = 2


drop table Sale
go
drop table Employee
go



SQl Server 2000 solution:  http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_20177696.html?query=xml+result+set&topics=42
jflannerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Anthony PerkinsCommented:
If the query method returns an untyped XML and you want a resultset, should you not be using OPENXML?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.