T-SQL to print A00 to Z99 and 0A0 to 9Z9 and 00A to 99Z

·

1 min read

with abc as (
SELECT a= ascii('A')
UNION ALL
SELECT a=a+1 
FROM abc WHERE a < ascii('Z')
), 
num
AS
( 
SELECT c=0 
UNION ALL
SELECT c=c+1 
FROM num WHERE c < 9
)  
SELECT char(a) +  str(n1.c,1) +  str(n2.c,1) FROM abc cross join num n1 cross join num n2
UNION ALL
SELECT  str(n1.c,1) + char(a)  +  str(n2.c,1) FROM abc cross join num n1 cross join num n2
UNION ALL
SELECT  str(n1.c,1) +  str(n2.c,1) + char(a) FROM abc cross join num n1 cross join num n2