I got my answer :)
/ me calls his hat google again.
Definitions
This means that I want a shortened URL. so i paste it in db to get a unique id. Then I convert this int / big int to base36 string.
Links I have disabled my code.
...
CREATE FUNCTION [dbo].[ConvertIntegerToBase36]
(
@IntegerValue INTEGER
)
RETURNS VARCHAR(50)
AS
BEGIN
DECLARE @Result VARCHAR(100) = '',
@ShortCharacterSet VARCHAR(36) = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
WHILE @IntegerValue > 0 BEGIN
SET @Result = SUBSTRING(@ShortCharacterSet, @IntegerValue % LEN(@ShortCharacterSet) + 1, 1) + @Result;
SET @IntegerValue = @IntegerValue / LEN(@ShortCharacterSet);
END
RETURN @Result
END
...
CREATE FUNCTION [dbo].[ConvertBase36ToInteger]
(
@EncodedValue VARCHAR(MAX)
)
RETURNS INT
AS
BEGIN
DECLARE @Result INTEGER = 0,
@Index INTEGER = 0,
@ShortCharacterSet VARCHAR(36) = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
WHILE @Index < LEN(@EncodedValue)
SELECT @Result = @Result + POWER(LEN(@ShortCharacterSet), @Index) *
(CHARINDEX
(SUBSTRING(@EncodedValue, LEN(@EncodedValue) - @Index, 1)
, @ShortCharacterSet) - 1
),
@Index = @Index + 1;
RETURN @Result
END
NTN.
source
share