You can at least quote every field from the database, whether it needs it or not -- it is still valid CSV. Don't know about Azure: in Oracle, you defined special chars with CHR(decimal_code) and concatenated separators and data with || so your field separator in the SQL looked like || CHR(34) CHR(44) CHR(34) ||
(which is why I used to build my queries in awk).
The downer is when data can contain double quotes. You need those doubled inside quoted fields, so :Said "Hello".
: becomes :"Said ""Hello""."
: and that is harder to do.
You can fix at most one field that can contain commas in awk. Suppose field 4 is the one that can have commas. You can cut off fields 1-3 and 5-NF, fully quote field 4, and reassemble the line as proper CSV. If that would help, comment me.
You can also have newlines inside CSV fields, which messes up columns per line too. This is also fixable in awk. Because newline is only valid in quoted fields, any line that has an odd number of quotes must be halfway through a data field, so you just read-ahead until you get an even number of quotes again.
sqlserver
tag)