Hi.. I wrote this query to return to me the data from Orders and [Order details] tables in the NorthWind database. My intention was to get an xml similar to this:

<Orders>
<Order orderid=''>
<OrderLines>
<OrderLine orderlineid=''>price</OrderLine>
</OrderLines>
</Order>
</Orders>

The script is here:
declare @table table(orderid int, detailid int, unitprice money)
insert into @table select o.orderid, od.productid, od.unitprice from
orders o join [order details] od on o.orderid = od.orderid
--select * from @table

select distinct 1 as tag, null as parent,
null as [Orders!1],
tab.orderid as [Order!2!orderid],
null as [OrderLines!3],
null as [OrderLine!4],
null as [OrderLine!4!orderlineid]
from @table tab

union all

select distinct 2 as tag, 1 as parent,
null as [Orders!1],
tab.orderid as [Order!2!orderid],
null as [OrderLines!3],
null as [OrderLine!4],
null as [OrderLine!4!orderlineid]
from @table tab

union all

select distinct 3 as tag, 2 as parent,
null as [Orders!1],
tab.orderid as [Order!2!orderid],
null as [OrderLines!3],
null as [OrderLine!4],
null as [OrderLine!4!orderlineid]
from @table tab

union all

select distinct 4 as tag, 3 as parent,
null as [Orders!1],
tab.orderid as [Order!2!orderid],
null as [OrderLines!3],
unitprice as [OrderLine!4],
detailid as [OrderLine!4!orderlineid]
from @table tab

order by [Orders!1], [Order!2!orderid], [OrderLines!3], [OrderLine!4], [OrderLine!4!orderlineid]
for xml explicit


But when I run this, I am getting <Orders> tag multiple times surrounding each of the <Order> tags. Could someone please correct me and put me in the right direction?
Thanks
rAma