Can someone give me an example of how to remove anything after a dash “-” in a zip code field using SQL commands?
For example, change any of this:
XXXXX-X
XXXXX-
XXXXX-XX
XXXXX-XXXX
to this:
XXXXX
Thanks for the examples. I also need to remove any instances of “-“, “-X’, “-XXXX”, etc in the databases so the zip codes just contain five digits. Can someone include an example of this?
Instead of using a regex, you could use MySQL’s
SUBSTRING_INDEX()method:EDIT (to support updates)
I’d recommend creating a second column, maybe
zip_code_shortand runningSET zip_code_short =instead of overwriting the main data – just to make sure it doesn’t cause any errors first (if feasible).