Jump to content

Remove variable substrings from fields


federico07

Recommended Posts

Hello,

I have a table as follows:

idProductBrand

1Pepsi prod1Pepsi

2Fanta prod2Fanta

3Coke prod3Coke

I need to remove the Brand prepended to the text included in Product column.

I need to get:

idProductBrand

1prod1Pepsi

2prod2Fanta

3prod3Coke

 

I tried the following query:

 

mysql_query("UPDATE table SET Product=REPLACE(Product, '$Brand', '')") or die(mysql_error());

 

but it does not work (it replaces only in the last row).

Is correct when placing a variable ($Brand) in the text to be replaced?

 

Does anybody know any UPDATE commands working on that?

 

Thanks

Link to comment
Share on other sites

Thanks. I tried this:

UPDATE table SET Product=REPLACE(Product, (UPPER(Brand)), '');

 

However the problem is the text I need eliminating -- referred to the example above -- could be in format PEPSI, pepsi, Pepsi. So I would need something 'universal' doing the job.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.