Solved

Export MSSQL table into XML data file.

Posted on 2013-01-03
3
929 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
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

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

Suggested Solutions

Title # Comments Views Activity
Help in SQL Full Text Search 3 28
XML to SQL Table using c# 5 47
SQL Select Prior Ship Date Data 2 31
BULK LOGGED - log full 9 15
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

759 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

25 Experts available now in Live!

Get 1:1 Help Now