Some product serial numbers are of type varchar and have a letter indicating the type followed by a number. The numbers are 0 padded up to 5 digits and we are approaching 'A100000'.
For the letters that have less than 100000 items they still want 0 padding up to 5 digits, and the letters that have more that 100000 to have more digits up to whatever number it is.
It currently finds the current max serial number something like this:
SELECT MAX(SerialNumber) FROM Table WHERE LEFT(SerialNumber, 1) = @leadingChar
However, using this method 'A99999' is selected over 'A100000' because 9>1. (Same reason Zoo is after Apple in a dictionary, more chars but less value in a leading char.)
So the problem is when it increments the current max serial number to get the next serial number after 'A99999' every time you get the new serial number you will get 'A100000'.
Splitting them to be a char column and int column in the database would be cumbersome since it is used in several tables and there are a few million total serial numbers.
It is written as a web app in vbscript/classic asp database is SQL Server 7.
If there are better tags/title feel free to edit/let me know.
Thanks for any help.