SSRS adding extra characters when exporting to CSV

1.4k Views Asked by At

I am creating an expression combining multiple fields into a single field in SSRS. However when I am exporting to CSV, some of the records are being appended with additional double quotes. How do I fix this?

Original Data:

SCode|BuildingNumber|StreetName|City|State|
---------------------------------------------
ABC|   |123 Street|New York   |NY|
DEF|   |456 Street|Los Angeles|CA|
IJK|123|7th Ave   |Chicago    |IL|
XYZ|   |789 Cir   |Atlanta    |GA|

Expression I am using:

=Fields!SCode.Value & "#" & IIF(IsNothing(Fields!BuildingNumber.Value), Fields!StreetName.Value, Fields!BuildingNumber.Value & "\," & Fields!StreetName.Value) & "#" & Fields!City.Value & "#" & Fields!State.Value"

Data after exporting to CSV:

ABC#123 Street#New York#NY
DEF#456 Street#Los Angeles#CA
"IJK#123, 7th Ave#Chicago#IL"
XYZ#789 Cir#Atlanta#GA

Thanks!

1

There are 1 best solutions below

6
Hannover Fist On

The CSV export should only be adding the text delimiter around a field if there's a delimiter character (a comma) or some sort of return charter.

Text qualifiers are added only when the value contains the delimiter character or when the value has a line break.

MS Docs

Check you text for commas, return characters, and line feeds.

Your examples don't have a comma but it may still have a return or line feed.

SELECT * 
FROM TABLE 
WHERE FIELD LIKE '%' + CHAR(13) + '%'
    OR FIELD LIKE '%' + CHAR(10) + '%'

The line feed and return characters are character numbers 10 and 13 in ASCII.