Home | Advertising Info17 USERS CURRENTLY ONLINE   
PowerASP
   Site Search Contact Us Thursday, March 28, 2024  

  Active InfoActive Info  Display List of Info MembersMemberlist  Search The InfoSearch  HelpHelp
  RegisterRegister  LoginLogin
Classic ASP - Code Samples
 PowerASP Code Help Area : Classic ASP - Code Samples
Subject Info: Pad With Leading 0’s A d d  -  P o s tAdd P o s t
Author
Message << Prev Info | Next Info >>
Bullschmidt
Newbie
Newbie
Avatar

Joined: July/06/2004
Location: United States
Online Status: Offline
Info: 12
Added: July/06/2004 at 1:30am | IP Logged Quote Bullschmidt

To pad with leading 0's up to 4 digits:
varFld = Right("0000" & varFld, 4)

- - - - -


To generate the next invoice number using as an example 0003 (i.e. there are leading zeros):

Use max in a totals SQL statement:
strSQL = "SELECT Max(tblInv.InvID) AS InvIDMax FROM tblInv"

And then add one to the one record's one field:
NewID = objRS("InvIDMax") + 1

And then add padding:
NewID = Right("0000" & NewID, 4)



__________________
J. Paul Schmidt, Freelance ASP Web Developer
www.Bullschmidt.com
Classic ASP Design Tips, ASP Web Database Sample (Freely Downloadable)
Back to Top View Bullschmidt's Profile Search for other info by Bullschmidt Visit Bullschmidt's Homepage
 
cwilliams
Admin Group
Admin Group
Avatar

Joined: April/26/2004
Location: United States
Online Status: Offline
Info: 137
Added: July/06/2004 at 12:35pm | IP Logged Quote cwilliams

Grabbing the next number in the database like that won't always work.

That is if your number ID field is a autonumber or auto increment field which it would most likely be.

For example when using MSACCESS if by chance the next number has been created and then deleted... (slim chance but it can happen)

If you use the method listed above you will get the wrong number because access will skip the one it deleted...  etc etc

I dont think that is an issue with SQL server though

There are also other scenarios when that will fail and get the wrong number.. like under multi user scenarios where another user might create a record right after you grab what you think is the next number... and before you actually create a record.

The best way to get the upcoming record number is of course to get it with your recordset at the same time you create that new record.

Your padding example though is clever and simple.



Edited by cwilliams on July/06/2004 at 3:08pm


__________________


Chris Williams
http://www.PowerASP.com
Back to Top View cwilliams's Profile Search for other info by cwilliams
 

If you wish to make a comment to this info you must first login
If you are not already registered you must first register

  A d d  -  P o s tAdd P o s t
Printable version Printable version

Info Jump
You cannot add new info in this area
You cannot add to info in this area
You cannot delete your info in this area
You cannot edit your info in this area
You cannot create polls in this area
You cannot vote in polls in this area

   Active Server Pages Rule The World
Contact Us  
All artwork, design & content contained in this site are Copyright © 1998 - 2024 PowerASP.com and Christopher J. Williams
Banner ads ,other site logos, etc are copyright of their respective companies.
STATS Unless otherwise noted - All Rights Reserved.

Active Server Pages asp source code database MS SQL MS Access .mdb adovbs.inc cookies calendar codes sql commands scripts asp programming tutorials iis web server components CJWSoft ASPProtect ASPBanner ASPClassifieds www.aspprotect.com, www.cjwsoft.com,www.aspclassifieds.com,www.aspphotogallery.com