************ *** TSQL *** ************ select applbatnbr, 'applbatnbr_leading_zeros' = replicate('0',(10-len(ltrim(rtrim(applbatnbr)))))+ltrim(rtrim(applbatnbr)) from ardoc *********** *** ASP *** *********** '--- Handle The Batch Number Increment For the Itinerary Number Set RSxchsdweb = CreateObject("ADODB.RecordSet") SQLQuery = "select sd_id04 from xchsdweb where setupid = 'SD'" On Error Resume Next RSxchsdweb.Open SQLQuery, ConnAppDB sParmDocNbr = trim(cStr(cdbl(RSxchsdweb("sd_id04")) + 1)) '-- since Itinerary Number has to be 6 characters, add 0's in the beginning iIndex = 1 iLength = len(trim(sParmDocNbr)) while iIndex <= (5 - iLength) sParmDocNbr = "0" & sParmDocNbr iIndex = iIndex + 1 wend RSxchsdweb.Close 'update the incremented value into xchsdweb table SQLQuery = "update xchsdweb set sd_id04 = '" & sParmDocNbr & "' where setupid = 'SD'" On Error Resume Next RSxchsdweb.Open SQLQuery, ConnAppDB If Err.number <> 0 then Call TMErrorHandler(ConnAppDB, "GRFUNCTION.ASP", SQLQuery) On Error Goto 0 ******************************************* *** Other Examples from Element K tips) *** ******************************************* ***************** *** VB Script *** ***************** function AddLeadingZeros( NumberToPad, TotalLength) AddLeadingZeros = Right( TotalLength, 10000000 + NumberToPad ) end function ***************** *** VB Script *** ***************** function LeadingZeros( Item, NumPlaces) LeadingZeros = Right(string(NumPlaces, "0") & Item, NumPlaces end function *********** *** ASP *** *********** Response.Write(format(567,"000000"))