Copy data from field A to field B only if field B is empty and vice-versa?


I have simple problem I’m trying to resolve for a friend of mine. Do to a script they were using and the way the template worked… they mixed around some data and now we are trying to put everything in one field.

The table name is:

In that table are two fields:

I need both fields to have identical data. Some listings have data in zipcode while other listings have data in pobox and other listings have data in both. Other listings have both fields blank.

  1. Both fields have similar data, but at one point the zipcode field had a length limit so it cut off some of the data. (ie: P.O. Box 157980 saved into the database as P.O. Box 1)

Other listings just have “P.O. Box” with no numbers.

  1. I was thinking of creating a 3rd field, so I can dump that data in that field and then just copy that data back into the zipcode field. Only because logically to me this seemed like it might be easier.

  2. In the 3rd field I was going to import all the zipcode data. Then import all the pobox data. Only overwriting existing with the field data being imported is not empty or contains a full P.O. Box number.

  3. So blank field entries can be overwritten, and fields that contain “P.O. Box” or “P.O. Box 1”(one number only) can be overwritten.

  4. If the field contains 10 characters or less (ie: “P.O. Box 1”) it should be over written, unless the field data being imported is blank or contains less than 10 characters itself. If it contains more than 10 characters then it probably contains the correct P.O. Box and shouldn’t be overwritten.

  5. After importing the data into the 3rd field, I want to copy it back into the zipcode field.

Thank you in advance.