Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Import XML files into SQL

Posted on 2011-09-15
3
Medium Priority
?
404 Views
Last Modified: 2012-05-12
Experts,

I need to import multiple XML files into a single SQL table. I need two things:

1)  I need SQL query to create a table in SQL from the XML file so I dont have to manually create the table.
2) I need SQL import query to import bulk XML files into the table created in (1). All the XML files will be saved in the same folder. I will schedule the import to run once a day so the SQL import query would import in all XML files received that day.

See attached two example XML files that we get from third parties. The XML file is suppose to be a standard format.  Any ideas?  

Thanks.

 70DAVIES-CA-EMP.XML 80BOTKIN-LD.XML
0
Comment
Question by:asmyatt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 2000 total points
ID: 36544314
HI.

Here are a few techniques / resources.

1. Use OPENROWSET(BULK 'your_xml_file_path', SINGLE_BLOB) as shown by SQL Server MVP, Plamen Ratchev -- http://pratchev.blogspot.com/2008/11/import-xml-file-to-sql-table.html

Note: Instead of INSERT INTO...SELECT, you could use SELECT...INTO to create table on the fly.

SQLTeam blog example -- http://weblogs.sqlteam.com/mladenp/archive/2007/06/18/60235.aspx -- showing similar approach but then bringing XML into XML data type versus parsing directly from OPENROWSET. From the XML column, you can parse XML later into table.

MSDN: http://msdn.microsoft.com/en-us/library/ms191184.aspx

2. Use BULK INSERT (Example D) from above MSDN -- http://msdn.microsoft.com/en-us/library/ms188365.aspx. You can use a staging table that just holds the XML, then have a procedure that automates storing this to a physical table after shredding the XML.

3. A bit dated, but use XML Bulk Load component (VBScript) -- http://support.microsoft.com/kb/316005. Along these lines, you could use .NET code in some fashion.

4. SSIS -- http://blogs.msdn.com/b/mattm/archive/2007/12/11/using-xml-source.aspx
MSDN: http://msdn.microsoft.com/en-us/library/ms140277.aspx
http://blogs.msdn.com/b/rdoherty/archive/2005/03/16/396956.aspx

Hope that helps!
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 36544340
I am not as SSIS savvy as I should be, so that should probably be #1 choice; however, I would probably end up one of the first two at the moment (that may change if I dive into the SSIS pool more -- again, as I think it is a good idea). Specifically, I would move data to a table containing an XML column and then I would do parsing in a routine as needed from there.
0
 
LVL 2

Author Comment

by:asmyatt
ID: 36544728
I'll have to dig into this - apparently not as easy as I was hoping...
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question