want to change value in record if size is less then 12

Discussion in 'Databases' started by hostingvoip, Feb 5, 2010.

  1. #1
    i am new for mysql, here is my question i hope you guys will help me to resolve this.

    i want a query for update if record is less then 12 Charc and want to make it 12 char with starting 0

    i.e i have record " 123456789123 " but if record is "123456789" where 3 char is missin from the starting means ( 000123456789 ) so i want to add 0 or 00 or 000 to make it 12 charc record.

    regards and thank in advanced for all.
     
    hostingvoip, Feb 5, 2010 IP
  2. anxggxun

    anxggxun Peon

    Messages:
    24
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    use the lpad function
    
    update tablename
    set recordname = lpad(recordname,12,'0')
    where "anyfilter"
    
    Code (markup):
    reference http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_lpad
     
    anxggxun, Feb 5, 2010 IP