Solved

Export MSSQL table into XML data file.

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql query Help 12 53
Benefits of SMB Fileshare 3 63
triggered use of sp_send_dbmail failure 2 23
Near realtime alert if SQL Server services stop. 20 56
This is basically a blog post I wrote recently. I've found that SARGability is poorly understood, and since many people don't read blogs, I figured I'd post it here as an article. SARGable is an adjective in SQL that means that an item can be fou…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
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).

896 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

16 Experts available now in Live!

Get 1:1 Help Now