Click to See Complete Forum and Search --> : ADDING LEADING 0 infront of a String
Bruce Lim
08-03-2004, 01:36 AM
HI
Does anyone know how to use ASP to add a leading 0 infront of a textfield(vchar). I am using SQL Server 2000 database.
For example
0001+1 = 0002 instead of 2
Thank you
buntine
08-03-2004, 04:14 AM
Well, if the field is of type String, then you just concatenate the zeros.
Dim val
val = "0002"
But im sure there is more to the problem than that.
The following may work, though I have not tested it.
Dim strVal, intVal
strVal = "0001"
intVal = CInt(strVal) + 1
Response.Write(intVal)
Regards,
Andrew Buntine.
zingmatter
08-04-2004, 12:06 PM
You can add 1000000 to you number then trim it...
num1 = 3
num2 = num1 + 1000000
'for a 5 digit number...
strNum = right(CStr(num2), 5)
strNum will now contain a string '00003'