Initials separated by periods (e.g. J.E.F. Smith) In a MySQL database I have a column that holds the initials of a person. However not all input is nice and clean. To give an example the initials for the name John Edward Fredrick Smith should be J.E.F.

Unfortunately in our database you would also find JEF or J.EF or JE.F. or J E F.

I thought I'd use the replace function to first remove all spaces and periods and then add periods after each letter. That last part (the adding a period after each letter) is the hard part. I just can't figure out how to do that in MySQL.

Any help would be much appreciated.

Vincent
You could probably write a function which looped over characters of the string to update any length string, but I'm guessing here you have a fairly limited range (i.e. you're unlikely to have records with more than four initials). If that's true you can do something like the following: 

-- Setup example table
create table people (initials varchar(1024));

insert into people (initials)
values
  ('JEF'),
  ('J.EF'),
  ('JE.F.'),
  ('J E F'),
  ('J.E F  F');

-- Remove all spaces
update people
set initials = replace(initials, ' ', '');

-- Remove all periods
update people
set initials = replace(initials, '.', '');

-- Add periods after each letter
update people
set initials = 
  case 
    when length(initials) = 1 then initials
    when length(initials) = 2 then concat(substring(initials, 1, 1), '.', substring(initials, 2, 1))
    when length(initials) = 3 then concat(substring(initials, 1, 1), '.', substring(initials, 2, 1), '.', substring(initials, 3, 1))
    when length(initials) = 4 then concat(substring(initials, 1, 1), '.', substring(initials, 2, 1), '.', substring(initials, 3, 1), '.', substring(initials, 4, 1))
    else initials
  end;


SQL Fiddle example: http://sqlfiddle.com/#!9/7fc7e/1

Edit: Note that I've used three separate update statements here to make it easier to understand, you could collapse this down to one or two statements if running this over a large table, to avoid multiple updates.