Software Tip: How To Export A Table To XML File In SQL Server Management Studio
There doesn’t seem to be a User Interface for exporting a table to an XML file in SQL Server Management Studio. It seems that Microsoft completely overlooked the case when you just need to do a one time export. The Import and Export Wizard that can be run from SQL Server Management Studio has options to export tables to many destinations, but oddly an XML file is not one of them. In the wizard, there are two options that have the letters XML in them, but I cannot get either one of them to work.

After many hours of searching the internet and trying different settings in the Export Wizard, I resigned myself to doing it manually. Here are the steps I took:
1. Open a new query window in SQL Server Management Studio.
2. Type in the select statement adding “for xml raw”.
3. Set the results to output in grid.
4. Execute the query.
5. Click on the link in the results pane.

This opens the resulting xml in a new query window.
6. Add the <root> </root> tags to the beginning and ending of the xml.
7. Save the resulting text to a file.


















Discussion Area - Leave a Comment