Dear Daniel:
Does every instance of this field currently in the database have all 4
commas? The first thing I'd do is to write a query to verify this fact,
showing all the rows that do not have exactly 4 commas. But, bear in mind,
even though you may find some consistency now, there is no guarantee of
consistency in the future when some user puts in more rows, unless you
somehow enforce the necessary rules.
In my (somewhat perverse) opinion, putting all this in one column of data
may or may not be a mistake. The way I have done in the past is to have
users enter an address just the way they want it to look when it is printed
on a label, with carriage returns (new lines), not the commas you have
shown. I then have a set of functions written that parse the address into
its components, and I display those components in controls on the screen
next to the address. I also publish the rules by which this parsing is to
be done. The parsing functions are then guaranteed to always parse the
whole address the same way, so there are no surprises. There are some
advantages to this, but I won't go into that now.
I mention this because you are stuck with the data you have. You will
probably need some parsing functions, whose particular rules will be
determined by the data you have. You will need this whether you choose to
leave the data as recorded, or whether you use parsing to produce values for
separate columns for the address components.
I recommend you not jump to any conclusions until you have used some
"scratch queries" to investigate just how much trouble you have to overcome.
I do have a function that will parse a string by any given character (in
your case, a comma) and return the Nth instance of that. For your sample,
this function, called 5 times, would give:
N Result
1 23 wheatfield way
2 warboys
3 huntingdon
4 cambridge
5 pe14 1dj
6 <null>
Let me know if that the thing for you, although writing it is a pretty good
exercise, so you should at least try it.
What do you think?
Tom Ellison