I am using a function to pull data from an SQL database and echo it to a file, to be subsequently e-mailed.
However some of the fields in the CSV file (when opened with Microsoft Excel) are showing leading/trailing spaces. 

Example of the SQL:

```
function pull_data
{
    sqlplus -s $user/$pass@$db <<EOF
    SET COLSEP ,
    SET LINESIZE 10000
    SET PAGESIZE 50000
    SET NEWPAGE NONE
    SET HEADING OFF
    SET FEEDBACK OFF
    SET ECHO OFF
    SELECT DISTINCT order_number,
                    TO_CHAR(entry_date,'DD/MM/YYYY'),
                    TO_CHAR(delivery_date,'DD/MM/YYYY'),
                    cust_name,
                    ...
}

echo "$(pull_data $a $b)" > $id.csv

```

Example of the spacing (couldn't upload through Stack Overflow):

<http://s3.postimg.org/ekgt9ig4f/Capture.png>

What can be done to get the output correct i.e. no leading or trailing spaces?