Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sql -> csv (with commas in data) 1

Status
Not open for further replies.

theEclipse

Programmer
Dec 27, 1999
1,190
US
I am doing a database extract to CSV for member addresses and cant figure out how to escape the ,'s that exist in my data so that they wont act as column seperators. I have tried backslashing them dynamically, but that doesnt help.

Has anyone ever overcome this one?
 
Have the fields seperated by quotes as well as commas. Most CSV parsers should be savvy enough to understand that anything in the quotes is part of the field (as long as they don't contain quotes as well!) and will thus ignore any commas inside of quotes. Otherwise it depends on the final output of the data in the CSV file... ie, if it's going to html you can change all the commas to , before making it a CSV file. I've mostly been using PERL to handle CSV files, but PHP should work as well.

Perl-Style Search and Replace:
Preg-Replace
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top