Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8361481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:42:43+00:00 2026-06-09T11:42:43+00:00

I have a MySQL table with a field of sequential numbers (MS-1, MS-2, …,

  • 0

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.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:42:44+00:00Added an answer on June 9, 2026 at 11:42 am

    take eggyal’s answer: https://stackoverflow.com/a/11809954/491243
    but if you want to permanently change its values the you can try this:

    UPDATE myTable
    SET columnA = CASE char_length(replace(columnA,'MS-', ''))
                       WHEN 0 THEN 'MS-0000'
                       WHEN 1 THEN CONCAT('MS-000', replace(columnA, 'MS-', ''))
                       WHEN 2 THEN CONCAT('MS-00', replace(columnA, 'MS-', ''))
                       WHEN 3 THEN CONCAT('MS-0', replace(columnA, 'MS-', ''))
                       ELSE        columnA
                  END
    

    myTable – change it to your original’s table name
    columnA – change to the name of your column which contains MS-* value

    As suggested by eggyal:

    UPDATE myTable 
    SET columnA = CONCAT('MS-',LPAD(SUBSTRING_INDEX(columnA,'-',-1),4,'0'))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL table called privatemessage with a primary key field called messageid.
I have multiple entries in a mysql table field, these are separated with commas;
I have a MySQL table with a primary key field that has AUTO_INCREMENT on.
I have a mysql table field set as time type which stores data in
I have a MySQL table called accounts . Within this table is a field
I have a MySQL table which has a product_id field (big integer) 1102330008 1102330025
I have the following MySQL table structure: num field company phone website 1 Gas
I have a MySQL table that has a field of comma separated values. How
I have a MySQL table where there is a 'date_added' (date) field, 'time_added' (time)
I have a MySQL table looking like this: > describe books; +---------------+--------------+------+-----+---------+----------------+ | Field

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.