, within csv

when a csv file has commas in its values, how can we make sure that the field value is imported correctly.

for example:

Bush, George should come in as one field not two.
LVL 5
25112Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

icenickCommented:
Hello,

It depends on how you specify the delimiter. If you specify your delimiter as comma ',' then  it will be successful. Otherwise, if your delimiter is a semi colon or tab it won't work.

Make sure you specify the delimiter correctly.

Good Luck!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gerwin Jansen, EE MVETopic Advisor Commented:
Either use a different separator or a fixed field width.
0
TommySzalapskiCommented:
Put quotes around the string field like this: "Bush, George"
It will open in Excel (and most other spreadsheet programs) without the quotes.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Gerwin Jansen, EE MVETopic Advisor Commented:
Correct, you have 3 options:

1 - choose a different separator - you have to make sure your separator will not be present in data
2 - put quotes around your field - you still have to make sure that " will not be present in data
3 - fixed field lenght - you have to be sure that field lengths are not too short

All methods have advantages/disadvantages, my advice is: choose one and stick to that. For instance, if you choose a different separator like TAB or | or : - make sure that your client applications cannot enter these characters in a field.
0
25112Author Commented:
the tool requires only csv.. if you put another delimiter, it is not more a csv, right? (comma separated)

i am generating the csv file data from a sql query.. to assign quote or proper length spaces are both going to be a challenge. any thoughts of alternatives?
0
Gerwin Jansen, EE MVETopic Advisor Commented:
I would go for option number 2, putting quotes around the field. In your query you can easily add the quotes between the fields like this:

select field1, '"' || field2 || '"', fiel3, field3
from table;

In the (oracle) sample above, field2 is your field that may contain spaces, output will look like this:

value1, "value2-last value2-first", value3

I'm trusting that your query already creates the , separators in the (spooled) output file.
0
Gerwin Jansen, EE MVETopic Advisor Commented:
Typo, I meant:

select field1, '"' || field2 || '"', field3
from table;
0
25112Author Commented:
good idea.. thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.