Exporting data from SSRS to a .csv file adds lots of quotation marks how do I get just one set?

Viewed 270

I have a report which is just a simple SELECT statement which generates a list of columns full of data. I want this data to be exported as a CSV file with each datum being enclosed in " quotation marks. I have created a table and used this as my expression

   =""""+Fields!Activity_Code.Value+""""

When I run the report inside ReportBuilder 3.0 I get exactly what I'm looking for

enter image description here

No headers and each datum has quotation marks, perfect.

But when I hit export to csv, and then open with notepad I see this.

enter image description here

The headers are in there where they shouldn't be and each datum has 3 quotation marks on each side. What am I doing wrong?

1 Answers

This is perfectly normal.

When csv fields contain a separator or double quotes, the fields are enclosed in double quotes and the quotes inside the fields are escaped with another quote.

Example - the fields:

123
"27" monitor"
456

become:

123,"""27"" monitor""",456

or:

"123","""27"" monitor""","456"

A csv reader/parser should handle this correctly when reading the data (or you could provide a parameter telling the parser that the fields are quoted).


On the other hand, if you just want your fields to be quoted inside the csv (and not visible after opening the file), you can tell the csv generator to quote the fields (or in this case do nothing since the generator seems to be adding quotes already).

Related