Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How to export SQL data to XML file Expand / Collapse
Author
Message
Posted Friday, December 14, 2012 8:00 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, January 21, 2014 11:30 AM
Points: 21, Visits: 160
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
Post #1396679
Posted Friday, December 14, 2012 8:27 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 3:44 PM
Points: 11,970, Visits: 10,995
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 Moden's 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)
Post #1396692
Posted Tuesday, December 18, 2012 4:08 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Today @ 1:12 AM
Points: 15, Visits: 432
If you have permission to execute xp_cmdshell then you can use SQLCMD for the same.

thanks,
Saurabh
Post #1397676
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse