用SQL计算基数36

时间:2014-06-02 15:11:36

标签: sql sql-server tsql

我似乎无法找到有关如何执行此操作的任何信息。关于如何从基数36转换而不是如何进行计数的大量文章。我需要从0000到zzzz。有没有人这样做过?

1 个答案:

答案 0 :(得分:2)

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