<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sqlserver007 &#187; BCP</title>
	<atom:link href="http://www.sqlserver007.com/tag/bcp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sqlserver007.com</link>
	<description>Blog on SQL SERVER and Business Intelligence  by Vivekanand Serou</description>
	<lastBuildDate>Fri, 21 May 2010 11:37:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Procedure to export text files</title>
		<link>http://www.sqlserver007.com/2009/09/23/procedure-to-export-text-files/</link>
		<comments>http://www.sqlserver007.com/2009/09/23/procedure-to-export-text-files/#comments</comments>
		<pubDate>Wed, 23 Sep 2009 11:32:46 +0000</pubDate>
		<dc:creator>Vivek</dc:creator>
				<category><![CDATA[TSQL Development]]></category>
		<category><![CDATA[BCP]]></category>
		<category><![CDATA[Export]]></category>

		<guid isPermaLink="false">http://www.sqlserver007.com/?p=250</guid>
		<description><![CDATA[Recently I have read a lot of Blog posts on how to export files in different formats. But I use a custom procedure which exports text files in Pipe Delimited format using BCP.This procedure can be used in other processes for Output and Error Handling. Here is the Script for the procedure.You can modify the [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I have read a lot of Blog posts on how to export files in different formats. But I use a custom procedure which exports text files in Pipe Delimited format using BCP.This procedure can be used in other processes for Output and Error Handling.</p>
<p>Here is the Script for the procedure.You can modify the below procedure using any of the delimiters.</p>
<pre>
alter procedure Export_To_TextFile
(
	@OutputQuery varchar(5000)
	,@FileLocation varchar(400)
	,@FileName varchar(1000)
	,@ServerName varchar(100)
)

as

Declare @bcpcommand varchar(8000)

set @bcpcommand = 'bcp "' + @OutputQuery + '" queryout ' + @FileLocation + @FileName + ' ' + CHAR(13)
+ '-c -t" | " -T -S ' + @ServerName

Exec master..xp_cmdshell @bcpcommand 
</pre>
<p>Here is how I call the procedure </p>
<p><img src="http://www.sqlserver007.com/wp-content/uploads/2009/09/ExportToTextFile_Results1.png" alt="ExportToTextFile_Results" title="ExportToTextFile_Results" width="408" height="105" class="aligncenter size-full wp-image-257" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sqlserver007.com/2009/09/23/procedure-to-export-text-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
