/*Only works if you are the destination folder
is on the database server hard drive. I.e., if attempting to execute this from blofeld, you need to remote into blofeld and create the destination.
Reference : http://craftydba.com/?p=1690
*/
/* BCP - Export whole table, txt format, trusted security, character format */
DECLARE @bcp_cmd1 VARCHAR(1000);
DECLARE @exe_path1 VARCHAR(200) =
' cd C:\Program Files\Microsoft SQL Server\100\Tools\Binn\ & ';
SET @bcp_cmd1 = @exe_path1 +
' BCP.EXE stuart_sandbox.dbo.dealers out ' +
'C:\temp\exportTest\dealerExport.csv -T -c ';
PRINT @bcp_cmd1;
EXEC master..xp_cmdshell @bcp_cmd1;
GO