SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Feb 2004
    Location
    newcastle, uk
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    auto_increment with leading zero's?

    Hi is it possible to have an auto_increment integer which increases like this

    0001
    0002
    0003

    etc rather than 1, 2, 3?

    I cant get mysql to recognise the zeros, but need to input job numbers automatically and they need the zeros

    cheers
    gray

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,014
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    why are you inputting auto_increment numbers?

    just display them with leading zeroes whenever you select them

    i remember once testing the ZEROFILL attribute, which is exactly what you need here, but couldn't get it to work

    therefore, i did it myself:

    select right(concat('00000',id),4) as zerofilled_id ...
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Guru SharifTK's Avatar
    Join Date
    Jan 2004
    Location
    New York, NY
    Posts
    621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I prefer not to mess with the auto_increment counter at all, not at the databases side, but you can format it when displaying like r937 has shown.
    SK

  4. #4
    SitePoint Member
    Join Date
    Feb 2004
    Location
    newcastle, uk
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    cool thanks guys


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •