Samer Nachabé
Samer Nachabé

Reputation: 943

Export XML data type column with Microsoft SQL Server Management Studio

I have a table with 2 columns. The column response is an XML data type column (I am able to click on it an open the XML document). I would like to have a code that would export each row of the column response into an XML document saved on my desktop. Path = C:\Users\SAM\Desktop\Folder.

So I would have an XML document for each row.

Output:

 SELECT * FROM Table

 Data           Response
20130101    <Getresponsequ…
20130102    <Getresponsequ…
20130103    <Getresponsequ…
20130104    <Getresponsequ…
20130105    <Getresponsequ…
20130106    <Getresponsequ…

I am using Microsoft SQL Server Management Studio.

Thanks in advance!

Upvotes: 2

Views: 3338

Answers (1)

jhmt
jhmt

Reputation: 1421

You can use bcp Utility to export query results to xml files.
It can be used from command prompt.
For example:

bcp "SELECT Response FROM [DB].dbo.[Table] WHERE Data = '20130101'" queryout "C:\Users\SAM\Desktop\Folder\20130101.xml" -c -S {ServerName} -U sa -P {password}

Upvotes: 1

Related Questions