convert(varchar, TextData)) does not have the length of varchar soecified.
By default it's equal to convert(varchar(30), TextData)).
And actually you do not need to convert Textdata at all.
Use PATINDEX instead of CHARINDEX.
_____________
Code for TallyGenerator