SQLtoCSV produces well formatted CSV documents from SQL queries, even where the data results contain line breaks, speech marks, quotes and commas.
Latest Release: https://github.com/deeja/SQLtoCSV/releases/latest
The reason this thing exists: SSMS’s export doesn’t work.
SMSS = Microsoft’s SQLServer Management Studio
If we have basic data (no line breaks or commas), then we can use MSSQL Management Studio to export basic data to CSV:
There is also the option of the copy/paste functionality to copy data into Microsoft Excel or another spreadsheet application.
These both work alright and most of the time you can get away with them without issue.
The problem is when the data starts to get tricky. If you have line breaks, it starts to mess with the output, and the CSV ends up broken.
Kind of how this seeming innocent data:
Produces this catastrophe using the “Save As [CSV]” built into MSSQL:
Whereas, if you use the SQLtoCSV tool above, it produces:
Now go use it!
https://github.com/deeja/SQLtoCSV/releases/latest
Thanks to Josh Close for maintaining CsvHelper and for effortlessly handling all the awful CSV I have to deal with regularly.