﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Programming / XML  / import and shred xml file to sql 2008 table (openrowset) / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Thu, 23 May 2013 04:12:57 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: import and shred xml file to sql 2008 table (openrowset)</title><link>http://www.sqlservercentral.com/Forums/Topic1391450-21-1.aspx</link><description>No problem....thanks for the feedback</description><pubDate>Mon, 03 Dec 2012 05:43:20 GMT</pubDate><dc:creator>arthurolcot</dc:creator></item><item><title>RE: import and shred xml file to sql 2008 table (openrowset)</title><link>http://www.sqlservercentral.com/Forums/Topic1391450-21-1.aspx</link><description>Hi SSComitted,... this worked like a charm - you really helped me out a lot here, thanks again and have a good time !greetings from Munich, Michael F.</description><pubDate>Mon, 03 Dec 2012 05:37:55 GMT</pubDate><dc:creator>Michael F-386896</dc:creator></item><item><title>RE: import and shred xml file to sql 2008 table (openrowset)</title><link>http://www.sqlservercentral.com/Forums/Topic1391450-21-1.aspx</link><description>Hi,I think the main thing that you was missing was the namespace declaration. I have also made a couple of minor alterations, namely the cross apply and removing the .query() methods in the select statement. I have come up with the following that gets the MAC address and the computer name from the example xml[code="sql"]WITH xmlnamespaces (DEFAULT 'urn:schemas-ts-fujitsu-com:software-preload')SELECT X.a.value('(SystemIdentification/MACAddresses/MACAddress/text())[1]', 'VARCHAR(30)') AS 'MAC',X.a.value('(OrderAttachements/PositionSpecificData/ClientParameters/ComputerName/text())[1]', 'VARCHAR(30)')FROM (SELECT CAST(x AS XML)FROM OPENROWSET(BULK 'd:\ExampleXml.xml',SINGLE_BLOB) AS T(x)) AS T(x)CROSS APPLY x.nodes('Systems/System') AS X(a);[/code]As I don't know the full schema of the XML, I wasn't sure if any of the nodes in the xpath repeat, but this should at least help get you on track.</description><pubDate>Sat, 01 Dec 2012 04:47:24 GMT</pubDate><dc:creator>arthurolcot</dc:creator></item><item><title>import and shred xml file to sql 2008 table (openrowset)</title><link>http://www.sqlservercentral.com/Forums/Topic1391450-21-1.aspx</link><description>Hello,I'm also trying to import certain fields of an xml-file into an existing sql table (neutc_import).Problem is: I get '0 rows affected' when I execute the query below.In the end I need to have mac-address and tcname for every machine in table neutc_import.I'm sure the query is wrong at least regarding the [u]"Cross Apply[/u]" statement.As you can see I am not very experienced with this type of stuff - so yourhelp is really appreciated - maybe just a small adjustment necessary (?)query:INSERT INTO neutc_import(macaddr,tcname)SELECT X.a.query('MACAddress').value('.', 'varchar(50)'),X.a.query('ComputerName').value('.', 'VARCHAR(50)')FROM (SELECT CAST(x AS XML)FROM OPENROWSET(BULK 'E:\scout_import\DSBU010995_Imdly_2_HwInfo.xml',SINGLE_BLOB) AS T(x)) AS T(x)CROSS APPLY x.nodes('records/record') AS X(a);referenced xml:&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;&amp;lt;Systems Version="4.00" xsi:schemaLocation="urn:schemas-ts-fujitsu-com:software-preload HWInfo4.00.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:schemas-ts-fujitsu-com:software-preload"&amp;gt;  &amp;lt;System&amp;gt;    &amp;lt;SystemIdentification&amp;gt;      &amp;lt;SerialNumber&amp;gt;DSBU010995&amp;lt;/SerialNumber&amp;gt;      &amp;lt;IndividualSoftwareID /&amp;gt;      &amp;lt;SystemUUID&amp;gt;{B2E832CC-7484-11E1-8B14-5026909B9A32}&amp;lt;/SystemUUID&amp;gt;      &amp;lt;CustomerSerialNumber /&amp;gt;      &amp;lt;IMEINumber&amp;gt;&amp;lt;/IMEINumber&amp;gt;      &amp;lt;MACAddresses&amp;gt;        &amp;lt;MACAddress type="OnBoard"&amp;gt;00:30:05:68:FF:BD&amp;lt;/MACAddress&amp;gt;      &amp;lt;/MACAddresses&amp;gt;    &amp;lt;/SystemIdentification&amp;gt;    &amp;lt;OrderReferenceData&amp;gt;      &amp;lt;P82OrderNumber&amp;gt;xxxxxxx&amp;lt;/P82OrderNumber&amp;gt;      &amp;lt;P82CustomerOrderNumber&amp;gt;xxxxxxx&amp;lt;/P82CustomerOrderNumber&amp;gt;      &amp;lt;P84OrderNumber&amp;gt;xxxxxxx&amp;lt;/P84OrderNumber&amp;gt;      &amp;lt;P84OrderPosition&amp;gt;100&amp;lt;/P84OrderPosition&amp;gt;      &amp;lt;P84CustomerOrderNumber&amp;gt;xxxxxxx&amp;lt;/P84CustomerOrderNumber&amp;gt;      &amp;lt;EndCustomerOrderNumber&amp;gt;xxxxxxx&amp;lt;/EndCustomerOrderNumber&amp;gt;    &amp;lt;/OrderReferenceData&amp;gt;    &amp;lt;ProductDetails&amp;gt;      &amp;lt;OrderCode&amp;gt;CUZ:KxxxVXXX-EMFxx&amp;lt;/OrderCode&amp;gt;      &amp;lt;Product&amp;gt;LB P771 BLACK     /CUZ:KxxxVXXX-EMFxx&amp;lt;/Product&amp;gt;    &amp;lt;/ProductDetails&amp;gt;    &amp;lt;SoftwareModules /&amp;gt;    &amp;lt;OrderAttachements&amp;gt;      &amp;lt;HeaderSpecificData /&amp;gt;      &amp;lt;PositionSpecificData&amp;gt;		&amp;lt;ClientParameters SubClient="None" Client="Caritas"&amp;gt;            &amp;lt;ComputerName&amp;gt;CNxxxxx&amp;lt;/ComputerName&amp;gt;            &amp;lt;OldComputerName&amp;gt;ONxxxxx&amp;lt;/OldComputerName&amp;gt;            &amp;lt;PrimaryContact&amp;gt;Max Mustermann&amp;lt;/PrimaryContact&amp;gt;		&amp;lt;/ClientParameters&amp;gt;      &amp;lt;/PositionSpecificData&amp;gt;    &amp;lt;/OrderAttachements&amp;gt;&amp;lt;/System&amp;gt;&amp;lt;System&amp;gt;&amp;lt;SystemIdentification&amp;gt;      &amp;lt;SerialNumber&amp;gt;DSBU010995&amp;lt;/SerialNumber&amp;gt;      &amp;lt;IndividualSoftwareID /&amp;gt;      &amp;lt;SystemUUID&amp;gt;{B2E832CC-7484-11E1-8B14-5026909B9A32}&amp;lt;/SystemUUID&amp;gt;      &amp;lt;CustomerSerialNumber /&amp;gt;      &amp;lt;IMEINumber&amp;gt;&amp;lt;/IMEINumber&amp;gt;      &amp;lt;MACAddresses&amp;gt;        &amp;lt;MACAddress type="OnBoard"&amp;gt;00:30:05:68:FF:BD&amp;lt;/MACAddress&amp;gt;      &amp;lt;/MACAddresses&amp;gt;    &amp;lt;/SystemIdentification&amp;gt;    &amp;lt;OrderReferenceData&amp;gt;      &amp;lt;P82OrderNumber&amp;gt;xxxxxxx&amp;lt;/P82OrderNumber&amp;gt;      &amp;lt;P82CustomerOrderNumber&amp;gt;xxxxxxx&amp;lt;/P82CustomerOrderNumber&amp;gt;      &amp;lt;P84OrderNumber&amp;gt;xxxxxxx&amp;lt;/P84OrderNumber&amp;gt;      &amp;lt;P84OrderPosition&amp;gt;200&amp;lt;/P84OrderPosition&amp;gt;      &amp;lt;P84CustomerOrderNumber&amp;gt;xxxxxxx&amp;lt;/P84CustomerOrderNumber&amp;gt;      &amp;lt;EndCustomerOrderNumber&amp;gt;xxxxxxx&amp;lt;/EndCustomerOrderNumber&amp;gt;    &amp;lt;/OrderReferenceData&amp;gt;    &amp;lt;ProductDetails&amp;gt;      &amp;lt;OrderCode&amp;gt;CUZ:KxxxVXXX-EMFxx&amp;lt;/OrderCode&amp;gt;      &amp;lt;Product&amp;gt;LB P771 BLACK     /CUZ:KxxxVXXX-EMFxx&amp;lt;/Product&amp;gt;    &amp;lt;/ProductDetails&amp;gt;    &amp;lt;SoftwareModules /&amp;gt;    &amp;lt;OrderAttachements&amp;gt;      &amp;lt;HeaderSpecificData /&amp;gt;      &amp;lt;PositionSpecificData&amp;gt;		&amp;lt;ClientParameters SubClient="None" Client="Caritas"&amp;gt;            &amp;lt;ComputerName&amp;gt;CNxxxxx&amp;lt;/ComputerName&amp;gt;            &amp;lt;OldComputerName&amp;gt;ONxxxxx&amp;lt;/OldComputerName&amp;gt;            &amp;lt;PrimaryContact&amp;gt;Max Mustermann&amp;lt;/PrimaryContact&amp;gt;		&amp;lt;/ClientParameters&amp;gt;      &amp;lt;/PositionSpecificData&amp;gt;    &amp;lt;/OrderAttachements&amp;gt;  &amp;lt;/System&amp;gt;&amp;lt;/Systems&amp;gt;Greetings from nice munich, Michael</description><pubDate>Fri, 30 Nov 2012 10:28:27 GMT</pubDate><dc:creator>Michael F-386896</dc:creator></item></channel></rss>