I have a MySQL table with a field of sequential numbers (MS-1, MS-2, ..., MS-100, ..., MS-800, etc.) These numbers are a unique identifier (not primary key) for a set of data. The problem is sorting. Is there a way to take this field and generate a new field to be used for sorting? It would need to take MS-1 and make it ms0001, MS-845 to ms0845, etc.
I need to end up with two fields: one that contains the original value (MS-1) and one that contains the normalized value "ms0001". The MS-1 will be used for display, while ms0001 will be used in a link.
Also, this field would need to be automatically generated for new rows.
Thanks!
Update: As suggested by eggyal, I tried this:
UPDATE Resources
SET collNum = CONCAT('MS-',LPAD(SUBSTRING_INDEX(eadFaUniqueIdentifier,'-',-1),4,'0')
Resources is the table in question,
collNum is the new field I'm trying to generate,
eadFaUniqueIdentifier contains the original value.
However, I get this error: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 2. (I'm using MySQL 5.1.61.)