Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Parent Child Hierarchy from SQL Server table

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hello all,

I have an interesting little issue which I think ought to be very simple to
resolve but I can't seem to come up with a way to do it. I have a SQL Server
table which contains a column whose value is a concatenation of an OrderID
and ItemID(with a separating dash). In other words line item 54 for order 35
would appear in the table as.
54-35

If I do a select on this table my order line item combinations come back in
the followign format

OrderNumber - ItemNumber

54-35
54-36
54-37
55-23
55-24
55-26

Here's my problem. I need to get this into XML format so that each order
appears only once in the XML as the parent node and each of its respective
items appears as a child node like the following:

<Order>54</Order>
<Item>35</Item>
<Item>36<Item>
<Item>37<Item>
<Order>55</Order>
<Item>23</Item>
<Item>24<Item>
<Item>26<Item>

I've tried every which way you can imagine to accomplish this using For XML
Explicit, or Recursive Stylesheet. I think I'm probably missing something
stupendously obvious and that's what's making this process so frustrating

Anybody run into something like this?

I would really appreciate any help you could provide.


thanks

carlos
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top