SQL – Output Data from SQL Server To File – BCP
The following BCP command selects data from a table called CUSTOMERS in the DATA database and exports it to a file called FOO_REPORT.CSV:
declare @bcpcommand varchar(1000)
SET @bcpcommand = ‘bcp “SELECT id, title, forename, surname, product FROM DATA.dbo.customers where product = ”FOO”” queryout C:\reports\FOO_REPORT.CSV -c -T”‘
EXEC master..xp_cmdshell @bcpcommand
You can also output to .XLS and .TXT.
Loading...
[...] http://robbamforth.wordpress.com/2008/11/03/sql-outout-data-from-sql-server-to-file-bcp/ [...]
How To Enable xp_cmdshell On SQL Server 2005 « Rob Bamforth’s Blog - May 5, 2009 at 4:46 pm