Solved

Import XML files into SQL

Posted on 2011-09-15
3
375 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
  • 2
3 Comments
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 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 59

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Query with Sum and Detail rows 2 50
create insert script based on records in a table 4 21
Help Required 2 33
SQL Error - Query 6 26
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

777 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