0

The filed length is varchar(7) I just want to set 0 before the ID number, for all rows as below:

TraineeID       TraineeID
   74            0000074
 1290            0001290
51315            0051315

Please help.

Regards Mir

Mir Abzal Ali
  • 569
  • 5
  • 9
  • 27
  • Use can use the format() function in mysql scripts and keep data saved as int. Not sure please describe better – Drew Jun 17 '15 at 18:51
  • If you don't want to alter the data within the database, then you could look into padding the zeros in the programming language using the data. For example in php: `sprintf("%07d", $row['TraineeID']);` – Siphon Jun 17 '15 at 18:54
  • @DrewPierce, I need to print it as same format or search with 7 character, Is there still way to keep it as int? – Mir Abzal Ali Jun 17 '15 at 19:07
  • Yes there is. Please keep the int tho first and foremost – Drew Jun 17 '15 at 19:11

1 Answers1

2

Try LPAD:

SELECT LPAD(TraineeID,7,'0');
Giorgos Betsos
  • 71,379
  • 9
  • 63
  • 98