I am working with Volusion and attempting to extract order data along with their related order details in a nested XML structure using SQL. The aim is to get each order along with its respective order details nested within it.
Here's a simplified version of the SQL query I'm working with:
SELECT
o.OrderID,
o.OrderDate,
o.OrderStatus,
od.OrderDetailID,
od.ProductCode
FROM
Orders o
LEFT JOIN
OrderDetails od ON o.OrderID = od.OrderID
WHERE
o.OrderDate >= '2016-01-01' AND o.OrderDate < '2016-02-01';
However, the XML output I’m receiving from this approach isn’t nested as intended, and instead, every order item produces a new order entry like so:
<Orders>
<OrderID>13971</OrderID>
<OrderDate>1/1/2016 12:09:00 AM</OrderDate>
<OrderStatus>Shipped</OrderStatus>
<OrderDetailID>147436</OrderDetailID>
<ProductCode>First Product</ProductCode>
</Orders>
<Orders>
<OrderID>13971</OrderID>
<OrderDate>1/1/2016 12:09:00 AM</OrderDate>
<OrderStatus>Shipped</OrderStatus>
<OrderDetailID>147437</OrderDetailID>
<ProductCode>Second Product</ProductCode>
</Orders>
...
Ideally, I'm trying to produce an XML structure along these lines:
<Orders>
<OrderID>13971</OrderID>
<OrderDate>1/1/2016 12:09:00 AM</OrderDate>
<OrderStatus>Shipped</OrderStatus>
<OrderDetails>
<OrderDetail>
<OrderDetailID>147436</OrderDetailID>
<ProductCode>First Product</ProductCode>
</OrderDetail>
<OrderDetail>
<OrderDetailID>147437</OrderDetailID>
<ProductCode>Second Product</ProductCode>
</OrderDetail>
...
</OrderDetails>
</Orders>
Despite various approaches and reviewing the Volusion schema, I'm unable to achieve the desired nested XML structure. Volusion support considers this to be an advanced use case and, unfortunately, doesn’t offer support for it.
Has anyone successfully generated a nested XML structure with Volusion data, and could you provide some guidance on how to achieve this?
Thank you in advance for your help!
Try Powershell script :