What happens when you get to "AAAZ" and want to add 1? Do you go to "AAAa" or "AABA" or "AAA0" or what? You need to be more specific still.
Set @c1=substring(@val,1,1)
Set @c2=substring(@val,2,1)
Set @c3=substring(@val,3,1)
Set @c4=substring(@val,4,1)
If @c4='Z'
Begin
Set @c4='A'
If @c3='Z'
Begin
Set @c3='A'
If @c2='Z'
Begin
Set @c2='A'
If @c1='Z'
Begin
Set @val=Null
End
Else
Set @c1=char(ascii(@c1)+1)
End
Else
Set @c2=char(ascii(@c2)+1)
End
Else
Set @c3=char(ascii(@c3)+1)
End
Else
Begin
Set @c4=char(ascii(@c4)+1)
End
If @val Is Null
Print 'Invalid value'
Else
Begin
Set @val=@c1+@c2+@c3+@c4
Print @val
End Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions in the SQL Server forum. Many of the ideas apply to all forums.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.