我有一个具有以下结构 OrderItems 的表
OrderId ProductName UnitPrice
1 Harley 1.0
1 Gloves 0.25
2 Gloves 0.25
By doing a select I would like to obtain something similar with :
<Order>
<OrderItem>
<OrderId>1</OrderId><ProductName>Harley</ProductName><UnitPrice>1.0</UnitPrice>
</OrderItem>
<OrderItem>
<OrderId>1</OrderId><ProductName>Gloves</ProductName><UnitPrice>0.25</UnitPrice>
</OrderItem>
</Order>
and
<Order>
<OrderItem>
<OrderId>2</OrderId><ProductName>Gloves</ProductName><UnitPrice>0.25</UnitPrice>
</OrderItem>
</Order>
目前我被困在
SELECT
t2.OrderId, t2.ProductName, t2.UnitPrice
FROM OrderItems t2,OrderItems t1 where t2.OrderId = t1.OrderId
FOR XML PATH('OrderItem') , ROOT('Order')