I have a table with the data:
itemID itemLocation quantity
-------------------------------------------------------
B008KZK44E COMMITED 1
B008KZK44E PRIME 1
B008KZK2LE COMMITED 1
I need to generate an xml with this node structure:
<inventoryItemData>
<itemID type="FAMILY">B008KZK2LE</itemID>
<availabilityDetail>
<itemQuantity>
<quantity unitOfMeasure="EA">1</quantity>
<itemLocation>COMMITED</itemLocation>
</itemQuantity>
</availabilityDetail>
</inventoryItemData>
<inventoryItemData>
<itemID type="FAMILY">B008KZK44E</itemID>
<availabilityDetail>
<itemQuantity>
<quantity unitOfMeasure="EA">1</quantity>
<itemLocation>COMMITED</itemLocation>
</itemQuantity>
</availabilityDetail>
<availabilityDetail>
<itemQuantity>
<quantity unitOfMeasure="EA">1</quantity>
<itemLocation>PRIME</itemLocation>
</itemQuantity>
</availabilityDetail>
</inventoryItemData>
The closer I get is this:
SELECT
'itemID' AS 'itemID/@type',
itemID AS 'itemID',
'' AS 'availabilityDetail',
'' AS 'availabilityDetail/itemQuantity',
'EA' AS 'availabilityDetail/itemQuantity/quantity/@unitOfMeasure',
quantity AS 'availabilityDetail/itemQuantity/quantity',
itemLocation AS 'availabilityDetail/itemQuantity/itemLocation'
FROM TABLE
FOR XML PATH ('inventoryItemData')
I'd appreciate any solution.
Thanks.