<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: SQLXML : How To Save XML Query Results to a File Using BCP</title>
	<atom:link href="http://www.sqlmusings.com/2009/03/21/sqlxml-how-to-save-xml-query-results-to-a-file-using-bcp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sqlmusings.com/2009/03/21/sqlxml-how-to-save-xml-query-results-to-a-file-using-bcp/</link>
	<description>ramblings, discoveries, tutorials on sql server and other database stuff</description>
	<lastBuildDate>Wed, 25 Jan 2012 06:55:33 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Sean</title>
		<link>http://www.sqlmusings.com/2009/03/21/sqlxml-how-to-save-xml-query-results-to-a-file-using-bcp/comment-page-1/#comment-5840</link>
		<dc:creator>Sean</dc:creator>
		<pubDate>Fri, 06 May 2011 10:48:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.sqlmusings.com/2009/03/21/sqlxml-how-to-save-xml-query-results-to-a-file-using-bcp/#comment-5840</guid>
		<description>The output from mine returned the following and did not create the file, as expected.

&lt;strong&gt;NULL
Starting copy...
NULL
1 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.) Total     : 1      Average : (1000.00 rows per sec.)
NULL&lt;/strong&gt;

The BCP line reads as follows:

&lt;strong&gt;bcp &quot;SELECT * FROM mytable FOR XML PATH(&#039;&#039;), ROOT(&#039;DATA&#039;), TYPE &quot; queryout C:\data\test1.xml -w -T -Smyserver&lt;/strong&gt;

I executed the query part which produced valid XML

&lt;strong&gt;SELECT * FROM mytable FOR XML PATH(&#039;&#039;), ROOT(&#039;DATA&#039;), TYPE&lt;/strong&gt;</description>
		<content:encoded><![CDATA[<p>The output from mine returned the following and did not create the file, as expected.</p>
<p><strong>NULL<br />
Starting copy&#8230;<br />
NULL<br />
1 rows copied.<br />
Network packet size (bytes): 4096<br />
Clock Time (ms.) Total     : 1      Average : (1000.00 rows per sec.)<br />
NULL</strong></p>
<p>The BCP line reads as follows:</p>
<p><strong>bcp &#8220;SELECT * FROM mytable FOR XML PATH(&#8221;), ROOT(&#8216;DATA&#8217;), TYPE &#8221; queryout C:\data\test1.xml -w -T -Smyserver</strong></p>
<p>I executed the query part which produced valid XML</p>
<p><strong>SELECT * FROM mytable FOR XML PATH(&#8221;), ROOT(&#8216;DATA&#8217;), TYPE</strong></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shawn in NC</title>
		<link>http://www.sqlmusings.com/2009/03/21/sqlxml-how-to-save-xml-query-results-to-a-file-using-bcp/comment-page-1/#comment-5774</link>
		<dc:creator>Shawn in NC</dc:creator>
		<pubDate>Thu, 24 Feb 2011 21:58:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.sqlmusings.com/2009/03/21/sqlxml-how-to-save-xml-query-results-to-a-file-using-bcp/#comment-5774</guid>
		<description>Thanks, Belle! I had everything going right, could read the XML in SSMS but not a browser.  Needed the little word &#039;TYPE&#039;. Your example saved my day, but I still need to go back and learn what in the world &#039;TYPE&#039; had to do with my XML failing.</description>
		<content:encoded><![CDATA[<p>Thanks, Belle! I had everything going right, could read the XML in SSMS but not a browser.  Needed the little word &#8216;TYPE&#8217;. Your example saved my day, but I still need to go back and learn what in the world &#8216;TYPE&#8217; had to do with my XML failing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lydia</title>
		<link>http://www.sqlmusings.com/2009/03/21/sqlxml-how-to-save-xml-query-results-to-a-file-using-bcp/comment-page-1/#comment-5568</link>
		<dc:creator>Lydia</dc:creator>
		<pubDate>Thu, 20 May 2010 15:44:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.sqlmusings.com/2009/03/21/sqlxml-how-to-save-xml-query-results-to-a-file-using-bcp/#comment-5568</guid>
		<description>I got error:
Error = [Microsoft][SQL Native Client][SQL Server]Login failed for user &#039;NT AUTHORITY\SYSTEM&#039;.
I checked the DB , it has user &#039;NT AUTHORITY\SYSTEM&#039;</description>
		<content:encoded><![CDATA[<p>I got error:<br />
Error = [Microsoft][SQL Native Client][SQL Server]Login failed for user &#8216;NT AUTHORITY\SYSTEM&#8217;.<br />
I checked the DB , it has user &#8216;NT AUTHORITY\SYSTEM&#8217;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew</title>
		<link>http://www.sqlmusings.com/2009/03/21/sqlxml-how-to-save-xml-query-results-to-a-file-using-bcp/comment-page-1/#comment-1444</link>
		<dc:creator>Andrew</dc:creator>
		<pubDate>Fri, 17 Jul 2009 02:35:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.sqlmusings.com/2009/03/21/sqlxml-how-to-save-xml-query-results-to-a-file-using-bcp/#comment-1444</guid>
		<description>This is very cool ... thanks so much for posting this.</description>
		<content:encoded><![CDATA[<p>This is very cool &#8230; thanks so much for posting this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: emime</title>
		<link>http://www.sqlmusings.com/2009/03/21/sqlxml-how-to-save-xml-query-results-to-a-file-using-bcp/comment-page-1/#comment-1356</link>
		<dc:creator>emime</dc:creator>
		<pubDate>Fri, 03 Jul 2009 09:13:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.sqlmusings.com/2009/03/21/sqlxml-how-to-save-xml-query-results-to-a-file-using-bcp/#comment-1356</guid>
		<description>I want to add a very important note. With bigger result sets I got a line brakes (and consequently the stored xml corrupted). The only thing that solved the problem was to add the options -r -t without argument. This instructs bps to override newline (default \n) and tab (default \t) with a null character (that is your final xml will not have line brakes or tabs but will be well formed!!!).
Furthermore, you can use batch to fix the limit size. Here the final instruction fragment for the bcp I used:
&lt;code&gt;
SELECT  @SQLCmd = &#039;bcp ... queryout ... -w -r -t -b 4000&#039;
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>I want to add a very important note. With bigger result sets I got a line brakes (and consequently the stored xml corrupted). The only thing that solved the problem was to add the options -r -t without argument. This instructs bps to override newline (default \n) and tab (default \t) with a null character (that is your final xml will not have line brakes or tabs but will be well formed!!!).<br />
Furthermore, you can use batch to fix the limit size. Here the final instruction fragment for the bcp I used:<br />
<code><br />
SELECT  @SQLCmd = 'bcp ... queryout ... -w -r -t -b 4000'<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: emime</title>
		<link>http://www.sqlmusings.com/2009/03/21/sqlxml-how-to-save-xml-query-results-to-a-file-using-bcp/comment-page-1/#comment-1350</link>
		<dc:creator>emime</dc:creator>
		<pubDate>Thu, 02 Jul 2009 16:01:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.sqlmusings.com/2009/03/21/sqlxml-how-to-save-xml-query-results-to-a-file-using-bcp/#comment-1350</guid>
		<description>Thanks, it&#039;s useful and worked for me. 
Just a note:
* the -S option is required only in case of remote execution of bpc. I had to cut it.
* VARCHAR(500) may be too much limiting</description>
		<content:encoded><![CDATA[<p>Thanks, it&#8217;s useful and worked for me.<br />
Just a note:<br />
* the -S option is required only in case of remote execution of bpc. I had to cut it.<br />
* VARCHAR(500) may be too much limiting</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: belle</title>
		<link>http://www.sqlmusings.com/2009/03/21/sqlxml-how-to-save-xml-query-results-to-a-file-using-bcp/comment-page-1/#comment-1017</link>
		<dc:creator>belle</dc:creator>
		<pubDate>Fri, 29 May 2009 18:55:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.sqlmusings.com/2009/03/21/sqlxml-how-to-save-xml-query-results-to-a-file-using-bcp/#comment-1017</guid>
		<description>Thanks John! :) Happy to hear that!</description>
		<content:encoded><![CDATA[<p>Thanks John! <img src='http://www.sqlmusings.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Happy to hear that!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John</title>
		<link>http://www.sqlmusings.com/2009/03/21/sqlxml-how-to-save-xml-query-results-to-a-file-using-bcp/comment-page-1/#comment-1016</link>
		<dc:creator>John</dc:creator>
		<pubDate>Fri, 29 May 2009 18:33:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.sqlmusings.com/2009/03/21/sqlxml-how-to-save-xml-query-results-to-a-file-using-bcp/#comment-1016</guid>
		<description>Less is more. Besides being short, sweet, and very elegant I use the little script in processing my XML almost every day.

Keep it up Belle!</description>
		<content:encoded><![CDATA[<p>Less is more. Besides being short, sweet, and very elegant I use the little script in processing my XML almost every day.</p>
<p>Keep it up Belle!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

