A machine produces xml files after testing. The problem is that the elements are all named the same but I need them to be in different columns.
Here is what the XML looks like:
<WorkProcess xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Header>
<Element>
<Name>
<string>CONTINENTAL_PART_NO</string>
</Name>
<Content>
<Header-Item>
<Name>Continental_Part_No</Name>
<Value>A2C73661103</Value>
<Comment />
</Header-Item>
</Content>
</Element>
<Element>
<Name>
<string>KENDRION_PART_NO</string>
</Name>
<Content>
<Header-Item>
<Name>Kendrion_Part_No</Name>
<Value>4191506A00-O</Value>
<Comment />
</Header-Item>
</Content>
</Element>
<Element>
<Name>
<string>PRODOCTION_DATE</string>
</Name>
<Content>
<Header-Item>
<Name>Prodoction_Date</Name>
<Value>20170222</Value>
<Comment />
</Header-Item>
</Content>
</Element>
<Element>
<Name>
<string>COUNTING_NO</string>
</Name>
<Content>
<Header-Item>
<Name>Counting_No</Name>
<Value>0068</Value>
<Comment>Count of IO-Parts</Comment>
</Header-Item>
</Content>
</Element>
From this XML i need the Name to be the column name and the Values to be in that column.
With my code:
DECLARE @XML AS XML, @hDoc AS INT, @SQL NVARCHAR (MAX)
SELECT @XML = XMLData FROM XMLwithOpenXML
EXEC sp_xml_preparedocument @hDoc OUTPUT, @XML
SELECT *
FROM OPENXML(@hDoc, 'WorkProcess/Header/Element/Content/Header-Item',2)
WITH
(Continental_Part_No [varchar](50) 'Value')
EXEC sp_xml_removedocument @hDoc
GO
Im only able to get all the values in 1 column because they all got the same path.
Is there any solution to manage this problem?
Thanks for your help!