Skanda (10/8/2012)
Hi,I need to write a SQL query to print the following aphanumberic sequence in SQL 2008.
0001, 0002, ... , 0009, 000A, ... , 000Z, ... , 0010, 0011, ... , 001A, ... and so on till... , ZZZZ
all characters should be in UPPERCASE.
Please Help me...
Thanks in advance
Here's a TSQL equivalent of the Oracle CTE:
SELECT
n,
CHAR(n + CASE WHEN n < 10 THEN 48 ELSE 55 END)
FROM (SELECT TOP(36) n = ROW_NUMBER() OVER (ORDER BY (SELECT NULL))-1 FROM sys.columns a, sys.columns b) t
ORDER BY n
Can you figure it out from here?
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden