Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update one column with a substr of another

Status
Not open for further replies.

akelabanda

Programmer
Dec 19, 2001
61
IN
Hello

I'm having a problem with an incorrect datafeed received.

Following is an example.

product_name column has this.
W880i Silver T-Mobile FLEXT 35 18 months

I now want to extract 'W880i Silver' which appears before T-Mobile and update the model_number column. This string can vary from record to record. But there is a pattern.

Another example:
C300 Virgin Mobile PAY AS YOU GO

Here I need 'C300' before 'Virgin Mobile'.

I would like to know how to capture the prefix while searching for a pattern like 'T-Mobile' and update another column model_number with the prefix.

Unable to figure out how to do this. Any help would be greatly appreciated.

Many thanks

Raj

UK's best mobile deals online
 
Ok. Looked at MySQL reference manual and figured out how to do it.

Here it is:

update mytable set model_number = substring_index(product_name,' T-Mobile ',1) where network = 'T-Mobile';

This worked beautifully.

UK's best mobile deals online
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top