SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to export SQL data to XML file


How to export SQL data to XML file

Author
Message
Kumar SQL
Kumar SQL
SSC-Enthusiastic
SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)SSC-Enthusiastic (115 reputation)

Group: General Forum Members
Points: 115 Visits: 176
Hi,

I have a sql data need to export to xml file; I can get data in xml mode using FOR XML PATH query and results are shown in xml style. When i click on xml link its opening in new tab with xml format exactly what i need.

But the problem is, i need to export that xml result into .xml file on my system. I tried by using "Results to file" option but unable to get what i need. Also i do not have bcp exceute permissions.

Can anyone please suggest me how to export those results to .xml file.

Thanks in advance!

Kumar
Sean Lange
Sean Lange
SSC Guru
SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)

Group: General Forum Members
Points: 62403 Visits: 17954
Kumar SQL (12/14/2012)
Hi,

I have a sql data need to export to xml file; I can get data in xml mode using FOR XML PATH query and results are shown in xml style. When i click on xml link its opening in new tab with xml format exactly what i need.

But the problem is, i need to export that xml result into .xml file on my system. I tried by using "Results to file" option but unable to get what i need. Also i do not have bcp exceute permissions.

Can anyone please suggest me how to export those results to .xml file.

Thanks in advance!

Kumar


Using the results to file with xml does not do exactly what you might think. Open the file with a text editor and you will see that it contains more than just the data from the query. It contains a column name, a line with a bunch of ------
Then your xml data.

then a line with xxx row(s) affected.

If you run your query with the results to file option you can save it as xml but you need to open it with a text editor and remove the additional junk it throws in there. Then you should be good to go.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Saurv
Saurv
SSC Rookie
SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)

Group: General Forum Members
Points: 32 Visits: 580
If you have permission to execute xp_cmdshell then you can use SQLCMD for the same.

thanks,
Saurabh
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search