Exported CSV data has extra fields
I built a clientEmailAddress report (see attached). The SQL is:
select c.party_id as id, c.description as email, REPLACE(REPLACE(REPLACE(e.name, '\n', ''), '\r', ''),char(0),'') as name, REPLACE(REPLACE(REPLACE(e.description, '\n', ''), '\r', ''),char(0),'') as address from contacts as c join entities as e on c.party_id=e.entity_id
where c.arch_short_name = 'contact.email' and e.arch_short_name='party.customerperson' and e.active=1;
If I run the SQL query (in say the MySQL Workbench), I get the data as expected, ie
45805 aaaa.test[at]bigpond[dot]com Aaatest,Aaaaa 123 Aaaa Street Shau Kei Wan Hong Kong Island - 1234 5678
When the report is run, the printed data also has things as expected.
However, if I click the Export button, then the resulting csv file has extra fields as follows:
CID,Email,Name,Address
45805,aaaa.test[at]bigpond[dot]com ,"Aaatest,Aaaaa",
,,,123 Aaaa StreetShau Kei Wan Hong Kong Island - 1234 5678
Note that the header line shows 4 fields, but a) there extra empty fields in the data lines between the Name and Address fields; b) there is a newline character after the comma following the Name field, and the Address data is not enclosed in quotes.
I think that this problem has to do with my use of the description field from the entities table without any removal of all non-printing characters. However, as you can see from the SQL I have done my best to strip newlines and nulls from both the name and address fields.
Any ideas?
Regards, Tim G
Re: Exported CSV data has extra fields
It might be related to non-printing characters. I've adapted the following SQL from http://stackoverflow.com/questions/11535350/remove-all-or-particular-non...
You use it as follows:
You probably want to replace '\n' and '\r' with space however.
-Tim A
Re: Exported CSV data has extra fields
Better yet, try using the convert function:
-Tim A