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 > Possible to use substring in an update query?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-02-05, 14:09
mrwiegand mrwiegand is offline
Registered User
 
Join Date: Jan 2005
Posts: 2
Possible to use substring in an update query?

I am attempting to take a field and break it into two seperate fields.
Using the select statement below I am able to see it broken into two fields

select name, substring(name, 1, instr(name, ',') - 1) first, substring(name, instr(name, ',') + 1) from doctor

OUTPUT
NAME | FIRST | LAST
Doe, John | John | Doe

What I am unsure about is how to turn this into an update query to place into the appropriate fields name 'first' and 'last'

Thanks in advance.
Reply With Quote
  #2 (permalink)  
Old 03-10-05, 17:36
rladda rladda is offline
Registered User
 
Join Date: Oct 2004
Posts: 6
update test a set first_name = (select substring(col_with_data,...)
from test b where <join a and b on key columns, columns that uniquely identify a row>)

and you can have the same query for last_name.

I am assuming you have blank columns already in the table.

I am not an expert, but hope this helps...
Reply With Quote
  #3 (permalink)  
Old 03-10-05, 17:59
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
does the table actually have 3 fields for fullname, firstname, lastname?
__________________
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