I have a table in SQL Server 2017 including XML-blobs and I want to convert the data into relational tables. I'm trying to use OPENXML and the sp_xml_preparedocument procedure in SQL Server. The XML-blob is a little bit special (as usual) and I can't find the right way to write the code. See the example. Please, anyone, help me
DECLARE @XML AS XML, @hDoc AS INT
SET @XML = '<reports xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:d1p1="http://www.uc.se/schemas/ucOrderReply/" d1p1:lang="swe">
<d1p1:report d1p1:id="6611231234" d1p1:name="Full name" d1p1:styp="F31" d1p1:index="0">
<d1p1:group d1p1:id="W080" d1p1:index="0" d1p1:key="" d1p1:name="ID-uppgifter, fysiker">
<d1p1:term d1p1:id="W08001">9761123768</d1p1:term>
<d1p1:term d1p1:id="W08002">6611231234</d1p1:term>
<d1p1:term d1p1:id="W08003">First name</d1p1:term>
<d1p1:term d1p1:id="W08004">Old road 174</d1p1:term>
<d1p1:term d1p1:id="W08005">17464</d1p1:term>
<d1p1:term d1p1:id="W08006">city</d1p1:term>
</d1p1:group>
</d1p1:report>
</reports>'
EXEC sp_xml_preparedocument @hDoc OUTPUT, @XML, '<reports xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:d1p1="http://www.uc.se/schemas/ucOrderReply/" d1p1:lang="swe"/>'
SELECT id--, name, W08001, W08002, W08003, W08004, W08005, W08006 -- This is what I want
FROM OPENXML(@hDoc, 'd1p1:reports/d1p1:report/d1p1:group/d1p1:term') -- I'm not sure about this path
WITH
(
id [varchar](50) '@id' -- This is not work
--, name
--, W08001
--, W08002
--, W08003
--, W08004
--, W08005
--, W08006
)
EXEC sp_xml_removedocument @hDoc
GO