Maksym Kozlenko has a nice solution, and others come close to unlocking it's full potential but then miss completely to realized that you can define any sequence of characters, and use it's length as the Base. Which is why I like this slightly modified version of his solution, because it can work for base 16, or base 17, and etc.
For example, what if you wanted letters and numbers, but don't like I's for looking like 1's and O's for looking like 0's. You can define any sequence this way. Below is a form of a "Base 36" that skips the I and O to create a "modified base 34". Un-comment the hex line instead to run as hex.
declare @value int = 1234567890
DECLARE @seq varchar(100) = '0123456789ABCDEFGHJKLMNPQRSTUVWXYZ' -- modified base 34
--DECLARE @seq varchar(100) = '0123456789ABCDEF' -- hex
DECLARE @result varchar(50)
DECLARE @digit char(1)
DECLARE @baseSize int = len(@seq)
DECLARE @workingValue int = @value
SET @result = SUBSTRING(@seq, (@workingValue%@baseSize)+1, 1)
WHILE @workingValue > 0
BEGIN
SET @digit = SUBSTRING(@seq, ((@workingValue/@baseSize)%@baseSize)+1, 1)
SET @workingValue = @workingValue/@baseSize
IF @workingValue <> 0 SET @result = @digit + @result
END
select @value as Value, @baseSize as BaseSize, @result as Result
Value, BaseSize, Result
1234567890, 34, T5URAA
I also moved value over to a working value, and then work from the working value copy, as a personal preference.
Below is additional for reversing the transformation, for any sequence, with the base defined as the length of the sequence.
declare @value varchar(50) = 'T5URAA'
DECLARE @seq varchar(100) = '0123456789ABCDEFGHJKLMNPQRSTUVWXYZ' -- modified base 34
--DECLARE @seq varchar(100) = '0123456789ABCDEF' -- hex
DECLARE @result int = 0
DECLARE @digit char(1)
DECLARE @baseSize int = len(@seq)
DECLARE @workingValue varchar(50) = @value
DECLARE @PositionMultiplier int = 1
DECLARE @digitPositionInSequence int = 0
WHILE len(@workingValue) > 0
BEGIN
SET @digit = right(@workingValue,1)
SET @digitPositionInSequence = CHARINDEX(@digit,@seq)
SET @result = @result + ( (@digitPositionInSequence -1) * @PositionMultiplier)
--select @digit, @digitPositionInSequence, @PositionMultiplier, @result
SET @workingValue = left(@workingValue,len(@workingValue)-1)
SET @PositionMultiplier = @PositionMultiplier * @baseSize
END
select @value as Value, @baseSize as BaseSize, @result as Result