Export SQL to Text

Posted by on November 7, 2011


Oddly I heard this question today.  It has been awhile but thought I would note for others for future reference the bcp command:

For a comma separated file:
From your sql server management studio run the below:
 
declare @sql varchar(8000)
 
SELECT @sql = ‘bcp “select * from [dbname]..[table name]” queryout c:\temp\mytest.txt -c -t, -T -S [server name]‘
 
exec master..xp_cmdshell @sql


ChatClick here to chat!+