MySQL Forums
Forum List  »  Newbie

Newbie needs help with what I expct is a simple query!
Posted by: Greg Hanley
Date: May 06, 2015 11:09PM

Hi guys

I have an MySQL table called "Products" that stores information about products.

It contains numerous fields but the 2 I am interested in are "id_product" and "reference".

"id_product" is int(10) and contains a unique number that identifies the product. "reference" is varchar(32) and can contain a reference number for the product. This could be the product number from the manufacturer for example.

I have over 1500 records in the table many of which do not have anything in the "reference" field. I would like a query that I could run that would automatically update the "reference" field to contain a combination the following:

RPRid_product

The "RPR" is simply a prefix that I would like to add at the beginning of the "reference code" and "id_product" is obviously the value contained in the "id_product" field.

So, for example, if the "id_product" of a record is "10" then the "reference" field would be "RPR0000010".

The "reference' field needs to be a length of 10 so the "id_product" needs to be "padded" with leading zero's.

I hope I have explained myself.

Thanks for any help you can provide.

Regards
Greg

Options: ReplyQuote


Subject
Written By
Posted
Newbie needs help with what I expct is a simple query!
May 06, 2015 11:09PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.