XML не правильно сформирован. Я должен был это исправить.
Вы действительно не поделились желаемым результатом, основываясь на фактическом XML. Пожалуйста, отредактируйте исходное сообщение и предоставьте желаемый результат.
А пока попробуйте SQL ниже. Это даст вам хороший старт.
SQL
-- DDL and sample data population, start
DECLARE @xml XML = N'<?xml version="1.0"?>
<ArrayOfFMADevice>
<FMADevice>
<DeviceID xmlns="http://www.fmaudit.com/">72979</DeviceID>
<CreationDate xmlns="http://www.fmaudit.com/">2017-04-12T02:13:44.257</CreationDate>
<Manufacturer xmlns="http://www.fmaudit.com/">RICOH</Manufacturer>
<Model xmlns="http://www.fmaudit.com/">MP C2004</Model>
<FMAMeter Version="4.4.85.17052">
<Date>2020-04-24T08:06:13.26</Date>
<Name>PageCountTotal</Name>
<Value>6193</Value>
</FMAMeter>
<FMAMeter Version="4.4.85.17052">
<Date>2020-04-24T08:06:13.26</Date>
<Name>PageCountMono</Name>
<Value>3159</Value>
</FMAMeter>
<FMAMeter Version="4.4.85.17052">
<Date>2020-04-24T08:06:13.26</Date>
<Name>PageCountPrinter</Name>
<Value>4919</Value>
</FMAMeter>
</FMADevice>
</ArrayOfFMADevice>';
-- DDL and sample data population, end
;WITH XMLNAMESPACES ('http://www.fmaudit.com/' AS ns1)
SELECT header.c.value('(ns1:DeviceID/text())[1]','VARCHAR(20)') AS [DeviceID]
, header.c.value('(ns1:CreationDate/text())[1]','DATETIME') AS [CreationDate]
, header.c.value('(ns1:Manufacturer/text())[1]','VARCHAR(20)') AS [Manufacturer]
, header.c.value('(ns1:Model/text())[1]','VARCHAR(20)') AS [Model]
, body.c.value('(Date/text())[1]','DATETIME') AS [Date]
, body.c.value('(Name/text())[1]','VARCHAR(20)') AS [Name]
, body.c.value('(Value/text())[1]','VARCHAR(20)') AS [Value]
FROM @xml.nodes('/ArrayOfFMADevice/FMADevice') AS header(c)
CROSS APPLY header.c.nodes('FMAMeter') AS body(c);
Выход
+----------+-------------------------+--------------+----------+-------------------------+------------------+-------+
| DeviceID | CreationDate | Manufacturer | Model | Date | Name | Value |
+----------+-------------------------+--------------+----------+-------------------------+------------------+-------+
| 72979 | 2017-04-12 02:13:44.257 | RICOH | MP C2004 | 2020-04-24 08:06:13.260 | PageCountTotal | 6193 |
| 72979 | 2017-04-12 02:13:44.257 | RICOH | MP C2004 | 2020-04-24 08:06:13.260 | PageCountMono | 3159 |
| 72979 | 2017-04-12 02:13:44.257 | RICOH | MP C2004 | 2020-04-24 08:06:13.260 | PageCountPrinter | 4919 |
+----------+-------------------------+--------------+----------+-------------------------+------------------+-------+