I agree that the problem is probably embedded line breaks in the data.
I also agree that exercising full control when formatting your CSV file is your best option. The CSV format that generally works best is:
- commas separating fields
- all non-numeric fields within double quotes, with any embedded double quotes doubled (i.e.,
John
becomes "John"
, and David "RD" Francis
becomes "David ""RD"" Francis"
)
By double-quoting your text, you can even have embedded line breaks handled properly.
You can modify a query to output data that's ready for a CSV file without too much difficulty:
Instead of:
SELECT first_name
,last_name
,company
...
Change to:
SELECT '"' + REPLACE(first_name, '"', '""') + '"' as first_name
,'"' + REPLACE(last_name, '"', '""') + '"' as last_name
,'"' + REPLACE(company, '"', '""') + '"' as company
...
This will change:
John Smith JSCo
Larry "Bud" Melman Worldwide Pants
Mike Jones Split
level name
Note that the thirs company name has a line break in it.
to:
"John" "Smith" "JSCo"
"Larry ""Bud""" "Melman" "Worldwide Pants"
"Mike" "Jones" "Split
level name"
Exported as CSV, this will open in Excel with that third company name in a single cell.