Solved

Export MSSQL table into XML data file.

Posted on 2013-01-03
3
955 Views
Last Modified: 2013-01-04
We are running MSSQL Server 2008.    How can I export a table of data into an XML file?
0
Comment
Question by:RichNH
[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
3 Comments
 
LVL 14

Accepted Solution

by:
Michael Dyer earned 500 total points
ID: 38742198
you can use SQL manager to run a query on the table with "For XML Auto" and then save the results.  This will get you an XML formatted file.

EXAMPLE

use database
select * from dbo.table
for XML AUTO
0
 
LVL 12

Expert Comment

by:Saurabh Bhadauria
ID: 38742932
Here is a simple example...

Declare @emp table (Emp_id int identity(1,1) , Emp_name varchar(150) ,Salary int  )

insert into @emp 
select 'a',100
union all 
select 'b',200
union all
select 'c',300 
union all 
select 'd',500

select * from @emp Employee for xml auto  , elements

Open in new window


But you can define output XML architecture through qurey....for example with elements above query   will give you different xml then withour elements cluase
0
 
LVL 1

Author Closing Comment

by:RichNH
ID: 38743452
Thank you both.   The first solution worked fine.   Took me a little bit to realize that I needed to click on the single link that was returned.  Now I think I just need to get past some sort of memory issue.  The file generated is several GB in size and the XML editor won't accept the entire thing.   I have exported the link out as a flat text file but there seems to be some sort of issue with record length.  Both when it comes out as filename.XML.CSV or when I simply say All Files in the file type when exporting and then name the file filename.XML there seems to be a natural record break at some byte limit where the <CR><LF> is inserted into the file.   I'm seeing this in the preview pane of Windows Explorer.  Perhaps this is just a natural condition of XML files which I have no experience in.  

In any case, the data did come out in XML format.   thank you.
0

Featured Post

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

Suggested Solutions

Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

733 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