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
113 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Complex SQL script 1 32
Concatenating multiple comments into one row 16 62
Unable to save view in SSMS 21 61
SQL Server Question 5 29
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…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

18 Experts available now in Live!

Get 1:1 Help Now