Thread: MS SQL Server General Questions/convert integer value into Base36 encoded string

convert integer value into Base36 encoded string
DECLARE @i int, @key int, @Base36 char(36), @Key5 varchar(5)
SET @key = 1234578910
SET @Base36 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
SET @Key5 = ''
SET @i = 1
WHILE @i < 6
BEGIN
   SET @Key5 = SUBSTRING(@Base36, (@key % 36)+1,1) +  @Key5
   SET @key = CAST(@key / 36 AS int)
   SET @i = @i + 1
END
SELECT @Key5



/* @identity_int passed in as a parameter */
DECLARE @i int, @key int, @Base36 char(36), @Key5 varchar(5),@ItsNew bit
SET @ItsNew = 0
WHILE @itsNew = 0
BEGIN

SET @key = @identity_int + 10000
/*
SET @Base36 = '0123456789ABCDEFGHIJKLMNOPQ9STUVWXYZ'
Randomize the order to generate numbers that look random.
*/

SET @Base36 = 'ZW2R4PGTK6XHFNOC9BIJML8DE5Q3S7UV1A0'
SET @Key5 = ''
SET @i = 1
WHILE @i < 6
BEGIN
SET @Key5 = SUBSTRING(@Base36, (@key % (36 - @i)+1),1) + @Key5
-- SET @key = CAST(@key / 36 AS int)
SET @i = @i + 1
END

END
SELECT @Key5