A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
Try this function:
create or alter function MyFunction( @N bigint )
returns varchar(max)
as
begin
declare @R varchar(max) = ''
declare @Chars varchar(max) = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
while 1 = 1
begin
set @R += substring( @Chars, (@N % len(@Chars)) + 1, 1)
set @N /= len(@Chars)
if @N = 0 break
end
return @R
end
Example:
select dbo.MyFunction( 324535354 )