If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Adding periods after MI in db that has some MI and periods to start

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-03-07, 15:40
hconnor hconnor is offline
Registered User
 
Join Date: Feb 2007
Posts: 34
Adding periods after MI in db that has some MI and periods to start

I'm trying to clean up a database that has middle initials in a field MI, but only a third of the records have a period after the MI.

I thought of going through letter by letter and doing something like this
UPDATE physician
SET physician_MI=REPLACE(physician_MI,'A','A.');

I tried that and if the letter has a period it ignores it and adds a period, so I have to do two steps, going back and replacing the two period letters. Not the end of the world, just checking to see if anyone has a better way of doing it maybe with a loop of the alphabet. (or two loops based on my results).

Thanks.
Reply With Quote
  #2 (permalink)  
Old 06-03-07, 16:18
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Code:
UPDATE physician
   SET physician_MI = CONCAT(physician_MI,'.')
 WHERE physician_MI not like '%.%'
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 06-04-07, 03:50
aschk aschk is offline
Registered User
 
Join Date: Mar 2007
Location: 636f6d7075746572
Posts: 770
I'm sure it's possible to use MySQL's regexp function also
e.g.
Code:
UPDATE physician
   SET physician_MI = CONCAT(physician_MI,'.')
 WHERE physician_MI REGEXP '^[a-zA-Z]{1,2}$';
Reply With Quote
  #4 (permalink)  
Old 06-04-07, 06:07
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
where did it say the middle initial could have only 1 or 2 characters?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On