Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
badman3k
Starting Member
15 Posts |
Posted - 2009-07-05 : 08:34:08
|
I'm trying to generate a stored procedure that will export certain data to a CSV file of my choice.I've had a look at BCP using similar to:declare @sql varchar(8000)select @sql = 'bcp master..sysobjects outc:\bcp\sysobjects.txt -c -t, -T -S'+ @@servernameexec master..xp_cmdshell @sql But it doesn't seem to work very well - i.e. not at all.Has anyone had any success in exporting a query result to a CSV file? How did you do it? Care to share?Any help or tutorials on the matter would be greatly appreciated.Many thanks in advance,Richard |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-07-05 : 10:19:40
|
make use of the format file and specify the comma delimiter in all columns except last one. For last column use \r\n for LF+CR KH[spoiler]Time is always against us[/spoiler] |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-07-05 : 13:03:40
|
also seehttp://www.nigelrivett.net/SQLTsql/BCP_quoted_CSV_Format_file.html |
 |
|
|
|
|