Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7579201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:37:04+00:00 2026-05-30T17:37:04+00:00

Is there a way of generating random base36 identifiers with a defined character count

  • 0

Is there a way of generating random base36 identifiers with a defined character count in SQL Server?

I have searched and found many examples of converting base 36 to int and vice versa, but not for randomly generating unique IDs.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T17:37:06+00:00Added an answer on May 30, 2026 at 5:37 pm

    This solution a bit verbose but works and can easily be adapted to a variety of requirements. Here’s some sample output:

    aapx0k  k4fdbb  vzbl5x
    8vr1bs  gbix1q  g5kctv
    he6e50  m9j0m0  2vz53l
    yw72hs  hgbo5h  3oen9v
    6t4q75  337670  5sf3h4
    yqr35s  xoh4hh  tc0wtf
    w7trkj  lnnpdk  zk2ln1
    1gt7qr  l6m72n  ja5kvm
    kg6f9y  6t3b7a  ujfr0i
    2jatgo  0yv8rv  wvbjfa
    

    Note that you need to create a view to wrap the use of RAND which is not allowed inside a UDF. So this solution needs two db objects, a view and a udf.

    CREATE VIEW ViewRandInt AS (SELECT RAND() * 36 as RandInt)
    GO
    
    CREATE FUNCTION GetRandomBase36Id
    (
        @charCount AS INT
    ) 
    RETURNS VARCHAR(50) AS BEGIN
    
        DECLARE @characters CHAR(36),
                @result VARCHAR(MAX),
                @counter INT,
                @randNum INT
    
        SELECT @characters = '0123456789abcdefghijklmnopqrstuvwxyz',
               @result = '',
               @counter = 0;
    
    
        WHILE @counter < @charCount
        BEGIN
            SELECT @randNum = RandInt FROM ViewRandInt
            SET @result = @result + SUBSTRING(@characters, @randNum+1, 1)
            SET @counter = @counter + 1
        END
    
        RETURN @result;
    
    END
    
    -- Test:
    SELECT dbo.GetRandomBase36Id(6), dbo.GetRandomBase36Id(6), dbo.GetRandomBase36Id(6)
    , dbo.GetRandomBase36Id(6), dbo.GetRandomBase36Id(6), dbo.GetRandomBase36Id(6)
    , dbo.GetRandomBase36Id(6), dbo.GetRandomBase36Id(6), dbo.GetRandomBase36Id(6)
    , dbo.GetRandomBase36Id(6), dbo.GetRandomBase36Id(6), dbo.GetRandomBase36Id(6)
    , dbo.GetRandomBase36Id(6), dbo.GetRandomBase36Id(6), dbo.GetRandomBase36Id(6)
    , dbo.GetRandomBase36Id(6), dbo.GetRandomBase36Id(6), dbo.GetRandomBase36Id(6)
    , dbo.GetRandomBase36Id(6), dbo.GetRandomBase36Id(6), dbo.GetRandomBase36Id(6)
    , dbo.GetRandomBase36Id(6), dbo.GetRandomBase36Id(6), dbo.GetRandomBase36Id(6)
    , dbo.GetRandomBase36Id(6), dbo.GetRandomBase36Id(6), dbo.GetRandomBase36Id(6)
    , dbo.GetRandomBase36Id(6), dbo.GetRandomBase36Id(6), dbo.GetRandomBase36Id(6)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way of generating random text which satisfies provided regular expression. I
Is there a way of generating a random number in ruby between, say, 1
Is there a way of automatically generating a HTML-Map compatible list of coordinates of
Is there a way to coax either the h:outputLink or s:link tags into generating
I am generating a document from HTML. Is there any way to force the
In PL/SQL Developer v7.1.x, is there way way to ignore large data types in
Is there a way in factory_girl to specify a random instance that an association
I've been trying to find a more pythonic way of generating random string in
I'm generating a random 10 character string with php, and inserting it into a
Hey guys I am making a 2D game and I have generating a random

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.