Exporting data from SQL Server Express to CSV (need quoting and escaping) Exporting data from SQL Server Express to CSV (need quoting and escaping) sql-server sql-server

Exporting data from SQL Server Express to CSV (need quoting and escaping)


It can be done! However you have to specifically configure SSMS to use quoted output, because for some daft reason it is not the default.

In the query window you want to save go to Query -> Query Options...

Check the box "quote strings containing list separators when saving .csv results".

enabling quoted csv output

then

select 'apple,banana,cookie' as col1,1324 as col2,'one two three' as col3,'a,b,"c",d' as col4

will output

col1,col2,col3,col4"apple,banana,cookie",1324,one two three,"a,b,""c"",d"

which is what we all want.


I've been trying to figure this out as well. Not sure if this will work for you since your table is much larger than mine, but this is what I did just out of a whim:

  1. I pulled up my table in Express by doing a SELECT * statement
  2. Simply selected the resulting rows and Ctrl + C
  3. Opened Excel
  4. Highlighted the amount of columns the table I was pasting had
  5. Pasted, and it friggin' worked!
  6. Now just have to Export Excel as CSV and done.

I know it probably sounds stupid, but it actually worked for me.


The easiest way to do this:

Use the Excel Data Import tools

  • Go to Data > From Other Sources > From Sql Server
  • Fill in the Server name etc.
  • Select the table or view that you want to import.

Then Save the imported data to a CSV file.If you want to export a query then save your query as a view