First, you need to understand how to generate a Base36 number in SQL (SQL Server in this case):
Here is an example, thanks to a previous question.
WITH num
AS (SELECT TOP 36 ROW_NUMBER() OVER(ORDER BY (SELECT 1)) AS i
FROM master.dbo.spt_values),
chr
AS (SELECT i, CASE WHEN i <= 10
THEN CHAR(i+47)
ELSE CHAR(i+54)
END AS c
FROM num)
SELECT t3.c + t2.c + t1.c + t0.c
FROM chr AS t3, chr AS t2, chr AS t1, chr AS t0
ORDER BY t3.i, t2.i, t1.i, t0.i
I won't explain the code, as I am getting my head around it as well. However, it uses a master table to get a sequence of numbers, starting from '1'. It's also using CTE.
Now you need to use this in a way, to convert datetime
values to Base36. Think of your datetime
as a value, which it is, like 4678.3783 for example. The integer
part is the date component. The decimal
part is the time component.