Writing CSV is Resulting in Extra Quotes

I am executing a stored procedure that returns a Name column that contains a set of double quotes around the value (“Smith, John”). However, when I write this output to a CSV to be uploaded to a system, the values in that column have two extra sets of double quotes around the values (“”“Smith, John”“”).

Does anyone have idea why this happens or how to fix it? Thanks in advance.

The double quote is a special character in CSV used to surround text fields, usually only if the field contains a space:
“text 1”,“text 2”,“text 3” => values text 1, text 2, text 3

In case the text field itself contains a doublequote it is “escaped” by another doblequote:
“text”“1”,“text”“2”,“text”“3” => values text"1, text"2, text"3

In case the text field itself is surrounder by doublequote it is “escaped” also resulting in 3 doublequotes :
“”“text1"”“,”““text2"””,“”“text3"”" => values “text1”, “text2”, “text3”

Cheers

Just curious Joska,

I saw that there was a trailing space after one of my columns’ headers in an Excel workbook. I used the read range activity (workbook) to get the data table with the headers included. Then I immediately inserted a write CSV activity with no specific encoding. My output filepath was a .txt format.

The column header with the trailing space had quotations wrapped around it when I viewed the TXT file. I’m not sure if this is similar with behavior you were mentioning and I’d like to know the reason exactly if you know. Why don’t spaces in between words become double quotes? For now I’ll try to remove the space in the excel before reading the DT, but it’s odd. Does choosing a specific encoding fix any of this? Is it even possible for a txt tab delimited file to have trailing spaces as part of the header?

Thanks!

See Comma-separated values - Wikipedia

In CSV implementations that do trim leading or trailing spaces, fields with such spaces as meaningful data must be quoted.

1997,Ford,E350," Super luxurious truck "

Cheers