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 > UPDATE using wildcard

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-29-07, 21:31
hconnor hconnor is offline
Registered User
 
Join Date: Feb 2007
Posts: 34
UPDATE using wildcard

Hi,

Is there a way to use wildcards to update this recordset? I've got a column with 'madison county, cook county, dupage county' and i'd like to change it to
'madison, cook, dupage'

I can make each change individually, but is there a simpler way?

update physician
SET physician_practice_County1 = 'Madison'
where physician_practice_County1= 'Madison County'

I tried the following:

update physician
SET physician_practice_County1 = '%'
where physician_practice_County1= '% County'

all help appreciated.
Reply With Quote
  #2 (permalink)  
Old 04-30-07, 06:05
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
why not just remove all occurrences of the word 'county' from the column, would that work?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 04-30-07, 17:48
hconnor hconnor is offline
Registered User
 
Join Date: Feb 2007
Posts: 34
Like this?

I tried this in a small test and it seems to work. Can you take a look and tell me if you see any errors? Thanks.

UPDATE physician
SET physician_practice_County1 =(REPLACE(physician_practice_County1 ,'County',''))
Reply With Quote
  #4 (permalink)  
Old 04-30-07, 17:50
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
looks great

i would write it without the parentheses around the function
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 05-03-07, 23:42
sco08y sco08y is offline
Registered User
 
Join Date: Oct 2002
Location: Baghdad, Iraq
Posts: 697
Quote:
Originally Posted by hconnor
Like this?

I tried this in a small test and it seems to work. Can you take a look and tell me if you see any errors? Thanks.

UPDATE physician
SET physician_practice_County1 =(REPLACE(physician_practice_County1 ,'County',''))
Pointing out the obvious: a WHERE clause would be a good idea here.
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