I cant seem to find any information on how to do this. Lots of articles on how to convert from base 36 but not on how to do a count. I need to count from 0000 to zzzz. Has anyone done this?
Asked
Active
Viewed 1,448 times
0
-
1What do you mean by count? Do you need routine to convert an integer to a b36 string? – Alex K. Jun 02 '14 at 15:15
-
3Count from 0 to 1679615, and convert to base-36 as you go. – Sergey Kalinichenko Jun 02 '14 at 15:16
-
I didn't think of converting as I go I was thinking in the way of counting 1-9 then a-z. Thanks for the idea I will look into converting as I go. – Turtleman10 Jun 02 '14 at 15:21
1 Answers
3
WITH
num AS (SELECT TOP 36 ROW_NUMBER() OVER(ORDER BY (SELECT 1)) i FROM master.dbo.spt_values),
chr AS (SELECT i,CASE WHEN i <= 10 THEN CHAR(i+47) ELSE CHAR (i+54) END c FROM num)
SELECT t3.c + t2.c + t1.c + t0.c
FROM chr t3, chr t2, chr t1, chr t0
ORDER BY t3.i, t2.i, t1.i, t0.i

Anon
- 10,660
- 1
- 29
- 31
-
Thanks for the solution for stupid problem. People add complexity to the data layer. Data could be stored in binary or numbers and represented to customer in the most convenient way. In that solution "0" can be mixed with "O" and "1" with "I", which adds complexity on a user layer. Whoever implementing that solution: Stop and think. – Slava Murygin Dec 28 '18 at 23:28
-
Would be good if @Anon would have explained what the code does and why? – Fandango68 Jul 01 '20 at 01:59