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 string

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

I need to update a record in table users where the record number is within a variable

the variable is called “ invoice” it’s value is G-123-456

I need to filter on just the 456 part of the variable.

UPDATE users
SET active=0
WHERE user_usr LIKE ‘ ‘’-’’-invoice

Not sure where to start on this.

Nick
Reply With Quote
  #2 (permalink)  
Old 11-15-10, 10:43
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
look at the MySQL string functions

on the face of it right looks promising
it should be trivial if there are always 3 characters to match. if not then you are going to have to dabble with the likes of instr to find where to start comparing
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 11-15-10, 11:14
dav1mo dav1mo is offline
Registered User
 
Join Date: Dec 2007
Location: Richmond, VA
Posts: 782
Or set up a column that just holds that piece of the invoice you are after. You could even set up a trigger to populate it at insert time.
Dave
Reply With Quote
  #4 (permalink)  
Old 11-15-10, 11:19
oldnickj oldnickj is offline
Registered User
 
Join Date: Jan 2009
Posts: 103
This is a the variable are from PayPal IPN which has ver limited number of fields to work with. I was hoping to put all the information I needed into a single field and parse it when I receive the notification. Would it help if I formatted it: G123IM456 then look for letters followed by numbers?
Reply With Quote
  #5 (permalink)  
Old 11-15-10, 12:29
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
look up the use of SUBSTRING_INDEX and leave the - in there to search on.
Reply With Quote
  #6 (permalink)  
Old 11-16-10, 02:41
bchanan bchanan is offline
Registered User
 
Join Date: Dec 2009
Posts: 27
better idea

why not use REGEXP and regular expression
since the expression is simple, it should work fast.

Check: MySQL :: MySQL 5.1 Reference Manual :: 11.5.2 Regular Expressions
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