+ Reply to Thread
Results 1 to 3 of 3

Thread: MySQL - comma delimited fields?

  1. #1
    fretwizz is offline x10Hosting Member fretwizz is an unknown quantity at this point
    Join Date
    Jun 2008
    Posts
    57

    MySQL - comma delimited fields?

    I have a database where one of the columns is named "Address" and it contains addresses, unfortunately, they are complete addresses in one column (I know this is a mistake but it's what I have to work with). The various parts of the address in this column are separated by a comma... like so:

    12345 Main St., Denver CO, 80202

    I created a couple of new columns, one for the zip code and one for the city and I then copied the data from the existing address column into my new columns (it took a little bit of effort but nothing compared to going through the entire database and entering it manually). I suppose I can leave the address column the way it is now that I have the data in my new zip and city columns to refer to... but I'd like to learn a bit about MySQL's capabilities and thought this might be a good place to do that. I've been looking for a way to extract and copy based on the comma delimited concept but I can't seem to find it. I've run across things that look similar (that I have tried on a smaller, test database) but they haven't panned out. Any ideas on how this can be done or places I can research to solve this problem (if it's even possible)?

    Thanks

  2. #2
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: MySQL - comma delimited fields?

    The place to look for MySQL's string manipulation capabilities is the string functions manual page. However, SQL isn't intended for string manipulation, hence MySQL's poor capabilities. A better solution would be to write a program in another language to perform the actual processing, perhaps using regular expressions.
    Code:
    /^\s*(\d+[^,]*\S)\s*,\s*(?:(?i)([^,]*(?:ste|apt|bldg|suite)[^,]*),(?i))?\s*([^,]+) ([A-Z]{2})\s*,\s*(\d{5}(?:-\d{4})?)\s*$/
    Last edited by misson; 02-01-2010 at 10:31 PM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  3. #3
    fretwizz is offline x10Hosting Member fretwizz is an unknown quantity at this point
    Join Date
    Jun 2008
    Posts
    57

    Re: MySQL - comma delimited fields?

    Thanks for the info!

+ Reply to Thread

Similar Threads

  1. [PHP] MySQL and PHP
    By Bryon in forum Tutorials
    Replies: 43
    Last Post: 03-24-2011, 07:27 AM
  2. Replies: 14
    Last Post: 09-29-2008, 07:07 PM
  3. sorting mysql data with the same fields
    By etomak26 in forum Programming Help
    Replies: 2
    Last Post: 09-08-2008, 07:51 PM
  4. New Site-Suggestions?
    By mnoutside in forum Review My Site
    Replies: 9
    Last Post: 08-27-2008, 07:01 AM
  5. Have a problem with my forum
    By tikloos in forum Scripts & 3rd Party Apps
    Replies: 43
    Last Post: 01-19-2006, 01:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers