I want to export some SQL Server 2005 data to CSV format (comma-separated with quotes). I can think of a lot of complicated ways to do it, but I want to do it the right<
I think the simplest way to do this is from Excel.
If you have a newer version of Excel you could bring the data in from PowerPivot and then insert this data into a table.
You can use following Node.js module to do it with a breeze:
https://www.npmjs.com/package/mssql-to-csv
SSIS is a very good way to do this. This can be then scheduled using SQL Server Agent jobs.
I had to do one more thing than what Sijin said to get it to add quotes properly in SQL Server Management Studio 2005. Go to
Tools->Options->Query Results->Sql Server->Results To Grid
Put a check next to this option:
Quote strings containing list separators when saving .csv results
Note: the above method will not work for SSMS 2005 Express! As far as I know there's no way to quote the fields when exporting results to .csv using SSMS 2005 Express.
set nocount on
the quotes are there, use -w2000 to keep each row on one line.
If it fits your requirements, you can use bcp on the command line if you do this frequently or want to build it into a production process.
Here's a link describing the configuration.