Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Serial characters

Author  Topic 

samir.first
Starting Member

34 Posts

Posted - 2014-02-25 : 03:37:20
I need Query
A
B
C
.
.
Z
AA
AB
.
.
AZ
AAA
AAB
. etc

nagino
Yak Posting Veteran

75 Posts

Posted - 2014-02-25 : 06:55:34
You select Chars
WITH BASE (letters, ascii) AS (
SELECT CHAR(65), 65
UNION ALL
SELECT CHAR([ascii]+1), [ascii]+1
FROM BASE
WHERE [ascii] < 90
), RESULT (letters) AS (
SELECT CONVERT(varchar(10), letters)
FROM BASE
UNION ALL
SELECT CONVERT(varchar(10), RESULT.letters + BASE.letters)
FROM RESULT
CROSS JOIN BASE
WHERE LEN(RESULT.letters) < 3
)
SELECT letters
FROM RESULT
ORDER BY LEN(letters), letters


-------------------------------------
From Japan
Sorry, my English ability is limited.
Go to Top of Page

samir.first
Starting Member

34 Posts

Posted - 2014-02-26 : 09:05:57
Incorrect syntax near 'RESULT'.
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2014-02-26 : 16:26:40
It looks like SQL is interpreting RESULT as a reserved word. Either make it a quoted-identifier (put square brackets) around it or rename it.
Go to Top of Page
   

- Advertisement -