I'm trying to export data from SQL Server into CSV format. I have a bat task to do this that's run at regular intervals. Command is:
C:\Program Files\Microsoft SQL Server\[...]\SQLCMD.EXE" -d [db details] -i c:\export.sql -o c:\export.csv -s"," -W
The SQL file is just a SELECT * from a view.
This works except that some of the rows have commas in the data, so the values need to be quoted. I could change the column separator to be "','", but then I'd need SQL Server to escape single quotes in the data as well.
Unfortunately changing the separator to another character is unlikely to solve the problem in 100% of cases as one of the fields contains serialized data from another application which contains all sorts of weird and wonderful characters.
Is there any way for me to get standard, quoted CSV data?