Results 1 to 3 of 3

Thread: Store number with leading 0's in DB

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2000
    Location
    Sussex, England
    Posts
    45

    Store number with leading 0's in DB

    I need to store a number in my SQL database in the form 0001, 0020, 0134 i.e. fixed at 4 digits. Does anyone have any idea how to do this ? This is a new requirement to an existing system hence i'd rather make a database change if possible ratehr than having to make changes to lots of ASP pages ...

    Thanks in advance
    Ian.
    Ian Clarke BSc (Hons) - Web Applications Programmer
    Ricardo Consulting Engineers Ltd.
    Email : [email protected]

  2. #2
    idover
    Guest
    i've never done this in microsoft's sql server, but i have done it in MySQL... in MySQL, you simply add the term ZEROFILL to your column description, also make sure to define the length that the number should be... in one situation, i had to have exactly six digits, so it was

    fieldName int(6) zerofill

    ... i'm sure that mssql has something similar... i'll look in a bit...

    if this is something that could be done after the data is retrieved from the server, you could easily convert it like this:

    Code:
    intResultNum = CInt(Right("0000" & intCurrentNumber, 4))
    good luck!

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2000
    Location
    Sussex, England
    Posts
    45
    Thanks for that, i ended up using a custom format function (as vbscript has'nt got one) that does the job, but your CInt solution looks even better !

    Ian.
    Ian Clarke BSc (Hons) - Web Applications Programmer
    Ricardo Consulting Engineers Ltd.
    Email : [email protected]

Posting Permissions

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



Click Here to Expand Forum to Full Width