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 > Parsing a field

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-18-11, 10:44
oldnickj oldnickj is offline
Registered User
 
Join Date: Jan 2009
Posts: 103
Parsing a field

I need to parse a field which contains a data string such as:
Pd 1/14/11, ck# 898, $295 dues 2/1/10-11/30/11

into separate fields like: paidDate, checkNumber, amount, type, subDate, endDate.

if this were a select statement I could trim or substr. but what would an update look like?

Thanks Nick
Reply With Quote
  #2 (permalink)  
Old 05-18-11, 12:24
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
use an application language like php

sql would be too messy

you're only going to do this once, right?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 05-18-11, 18:26
oldnickj oldnickj is offline
Registered User
 
Join Date: Jan 2009
Posts: 103
I was successful using the following statements:
UPDATE usersComment set pdDate =SUBSTR((SUBSTRING_INDEX((SUBSTRING_INDEX(staff_co mment_usr,',',2)),',',1)),4,8)

UPDATE usersComment set pdAmount=SUBSTR(SUBSTR(SUBSTRING_INDEX((SUBSTRING_ INDEX(staff_comment_usr,',',-1)),',',1),1,5),-3,5)

UPDATE usersComment set pdCheckNum =SUBSTRING_INDEX((SUBSTRING_INDEX(staff_comment_us r,',',2)),',',-1)

UPDATE usersComment set pdEffect=SUBSTR(SUBSTRING_INDEX(staff_comment_usr, '-',1),-7,8)

UPDATE usersComment set pdExpire=
SUBSTRING_INDEX((SUBSTRING_INDEX(staff_comment_usr ,'-',-1)),',',1)

Now I'd like to change the dates which are text to date format i.e.

The text is in this format mm/dd/yy (2/24/11) obviously just changing the field type doesn't work.

any ideas?

Nick
Reply With Quote
  #4 (permalink)  
Old 05-18-11, 18:56
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Quote:
Originally Posted by oldnickj View Post
Now I'd like to change the dates which are text to date
STR_TO_DATE function
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 05-18-11, 20:22
oldnickj oldnickj is offline
Registered User
 
Join Date: Jan 2009
Posts: 103
So eloquent!

Ta
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