The following code displays a trigger that I have created to generate an id number that always has to display as five characters. The field type is char but the id number format has to display as a character and 4 integers, for example: T0001. The problem is that the code will work if I increment the number using T1000 it will successfully increment to T1001. If I try incrementing from T0000 than the next number displays as T2. Any suggestions for code that would be able to populate the space after the the first character with leading zeros. The code is below: <br><br>CREATE TRIGGER doctoridITrig ON tjohnso.tstvalid_doc FOR INSERT AS<br>DECLARE @maxss char(5), @maxsd int, @chrDOC char(5) /* FOR COUNTER-EMULATION CODE */<br><br><br>/*<br> * Assign doctor id number<br> */<br><br>IF (SELECT Count(*) FROM inserted WHERE doctorid IS NULL) > 0<br> BEGIN<br> SELECT @chrDOC = (SELECT Max(doctorid) FROM tjohnso.tstvalid_doc WHERE <br> doctorid Like '%T%')<br>/*<br>The following code seperates the letter 'T' from the four numbers and places the numbers into a variable so that the id number can be incremented by 1<br> */<br> IF @chrDOC IS NULL SELECT @maxsd = convert(int,(substring(@chrDOC, 2,4)))<br> ELSE <br> BEGIN<br> SELECT @chrDOC = SUBSTRING(@chrDOC, 2,4)<br> SELECT @maxsd = CONVERT(int, @chrDOC)<br> END<br> SELECT @maxsd = @maxsd + 1<br> SELECT @chrDOC = CONVERT(char(5), @maxsd ) <br> <br> UPDATE tjohnso.tstvalid_doc SET doctorid = 'T' + @chrDOC WHERE doctorid IS NULL<br> END<br><br><br><br>GO<br><br>Any help or ideas would be greatly appreciated. Thank you.