Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello there.

Is there a way to maintain the format of a number in this form:

00238
00250

Initially those numbers are a string in the project and they are saved as varchar in my database, but I need to generate a consecutive serial from those two, to achieve that I pass the numbers to int, but with this the leading zeros are obviously removed.
Is just to clear my curiosity about it, I already save all the serials into the database with the leading zeros but I made this taking the length of the original string and making a comparison of the serial generated with the original.

Thanks in advance
Posted
Updated 21-Feb-13 4:49am
v2
Comments
CHill60 21-Feb-13 11:10am    
Just a thought - you will get better database performance if you stored these "numbers" as integers on the database. You will also future-proof yourself against the serial number clocking past 99999. You can always display/print them in the varchar format when required. Another advantage would be being able to have the d/base column defined with IDENTITY(1,1) meaning that the serial will be automatically incremented for you each time you add a row
EddyGuzman 21-Feb-13 11:42am    
Oh! Yes I know, I was saving them as Integers at start, problem is that this numbers are consecutive serials, so if I remove the zeros the serial will be incorrect. But your comment is absolutely valid.

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900