Solved

load xml file into a database so that I can see the data that is in the XML file

Posted on 2014-10-17
2
112 Views
Last Modified: 2014-10-17
Hi,
We have a very large xml file called GMEIIssuedFullFIle.xml

What would the SQL code be to...
load the file into a test database so that we can view the data that is in the xml file.

Thanks for your help in advance
0
Comment
Question by:tesla764
2 Comments
 
LVL 39

Accepted Solution

by:
lcohan earned 500 total points
ID: 40387006
You could do that for instance like in the query below assuming you know the structure of your XML doc:

CREATE TABLE [dbo].XMLtable_load(
      [bip] [varchar](10) NULL,
      [Doc_TYPE] [varchar](50) NULL,
      [Doc] [text] NULL,
      [ID] [varchar](50) NULL,
      [rowOrder] [int] NULL,
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO


INSERT INTO XMLtable_load (bip,doc_type,doc,id,roworder)
 SELECT X.bip.query('bip').value('.', 'VARCHAR(10)'),      
 X.bip.query('Doc_TYPE').value('.', 'VARCHAR(50)'),
 X.bip.query('Doc').value('.', 'VARCHAR(8000)'),
 X.bip.query('@ID').value('.', 'VARCHAR(50)'),
 X.bip.query('@rowOrder').value('.', 'INT')
 FROM
 ( SELECT CAST(x AS XML)FROM OPENROWSET(     BULK 'C:\Downloads\BipDocs.xml', SINGLE_BLOB) AS T(x)     )
 AS T(x)CROSS APPLY x.nodes('Root/bip_Doc') AS X(bip);
0
 

Author Closing Comment

by:tesla764
ID: 40387529
Thanks. That was very helpful.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this article I will describe the Detach & Attach 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.
In this article I will describe the Backup & Restore 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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now