?
Solved

Export MSSQL table into XML data file.

Posted on 2013-01-03
3
Medium Priority
?
963 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 2000 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

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