Can we auto increment alphabet & number in SQL

I have a column aaaz7 which is multiple of 7.
so, next value will follow as below

a1bz1
a1cz8
a1dz1
...
z9zz8

Is possible to do it?
SQL GuruAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SQL GuruAuthor Commented:
I have managed to achieve my functionality.But I feel code looks bit ugly. is there any better approach to solve this problem

declare @t table ( id int identity (1,1) , chars varchar(10))
DECLARE @TotalRowCount INT ,@DECREMENT INT = 0 ,@ASCII INT,@len INT ,@C VARCHAR(10)
insert into @t values('zyZ')
insert into @t values ('zzz')
insert into @t values ('zzz')


----------------------------------------------------------------

select @TotalRowCount = COUNT (ID) from @t 

WHILE (@TotalRowCount >= 0 )

  
  BEGIN
      
           SELECT @len = len(chars ) 
			from @t where id =@TotalRowCount 
			  SET @DECREMENT =0
			
		WHILE (@LEN > 0 ) 
			BEGIN 
			--SELECT  (reverse ( substring ( reverse (chars ) , 1 ,@DECREMENT + 1) )) ,@DECREMENT,ASCII (reverse ( substring ( reverse (chars ) , 1 ,@DECREMENT + 1) )) +1 
			--from @t where id =@TotalRowCount 

			SELECT @ASCII  = ASCII (reverse ( substring ( reverse (chars ) , 1 ,@DECREMENT + 1) )) +1 
			from @t where id =@TotalRowCount 

				   IF (@ASCII > 64 AND @ASCII < 91) OR ( @ASCII > 97 AND @ASCII < 123)
					  BEGIN 
						SELECT @C =CHAR(@ASCII) -- DO THE INCREMENT  AND EXIT 
						GOTO OUTOFLOOP
					   END
				       -- select '@DECREMENT +1 '
				        SET @DECREMENT = @DECREMENT +1 --find the next character 
						SET @LEN = @LEN -1 
			  END

			 SET  @TotalRowCount = @TotalRowCount -1 
			 IF (@TotalRowCount = 0) 
			 BEGIN
			      RAISERROR (50005, -- Message id.
							 10, -- Severity,
							1, -- State,
							N'All possible Series are Used');

					 THROW 50005, 'All possible Series are Used', 1;
			 END 
	END

	OUTOFLOOP:

	SELECT @C 

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ste5anSenior DeveloperCommented:
What are your rules here? And what is your use-case?
0
ste5anSenior DeveloperCommented:
Then post it, please.
0
SQL GuruAuthor Commented:
I found the solution on my own.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.