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

  • Home
  • SEARCH
  • 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 6190479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:35:47+00:00 2026-05-24T02:35:47+00:00

I am using the below in my stored procedure to create a 8 digit

  • 0

I am using the below in my stored procedure to create a 8 digit password and return it as output.

select @AuthKey = @AuthKey + char(n) from
(
    select top 8 number as n from master.. spt_values
    where type= 'p' and number between 48 and 57
    order by newid()
) as t 

But i want the output as alpha numeric value, instead of just numeric value. How can i get it ?

  • 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-24T02:35:48+00:00Added an answer on May 24, 2026 at 2:35 am

    Anuya — this is a very clever way to randomize values, using order by newid(). You can also use lowercase characters, if your passwords are case sensitive:

    declare @AuthKey varchar(255)
    set @AuthKey = ''
    select @AuthKey = @AuthKey + char(n) from
    (
        select top 8 number as n 
        from master..spt_values
        where type= 'p' and (
                (number between 48 and 57)  -- numbers
          or    (number between 65 and 90)  -- uppercase letters
          or    (number between 97 and 122) -- lowercase letters
        )
        order by newid()
    ) as t 
    print @AuthKey
    

    Using a slightly different approach, you could include a specific character set, including symbols:

    declare @AuthKey varchar(255), @chars varchar(255), @len int
    set @AuthKey = ''
    set @chars = '012345ACDFGIJKLMSTXYZ_-#@!'
    set @len = len(@chars)
    
    select @AuthKey = @AuthKey + chr.c
    from (
        select substring(@chars, num.n, 1) as c
        from (
            select top 8 number as n
            from master..spt_values
            where type='p' and (number between 1 and @len)
            order by newid()
        ) as num
    ) as chr
    print @AuthKey
    

    Of course this only includes any given character one time. Still it is a very clever way of generating passwords. Kudos!

    Edit:
    If you want to have the chance of having doubles, you can do it like this :

    declare @AuthKey varchar(255), @chars varchar(255), @len int
    set @AuthKey = ''
    set @chars = '012345ACDFGIJKLMSTXYZ_-#@!'
    set @len = len(@chars)
    
    SELECT TOP 8 @AuthKey = @AuthKey + SubString(@chars, 1 + Convert(int, ABS(BINARY_CHECKSUM(NewID())) % @len), 1)
      FROM master..spt_values
    

    (will be slightly faster too as the query doesn’t require sorting spt_values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the stored procedure below for the select command of a SqlDataSource,
I've created a stored procedure similar to the one below (I'm using this cut
below is the stored proc I wrote: create or replace procedure test005 as begin
I am using SQL Server 2005. I want to create a stored procedure that
I want to be able to get some output from mysql stored procedure within
I have a stored procedure which returns XML to the caller using a SELECT
Below is a simplified example of a stored procedure I've created. DELIMITER // CREATE
I want to create a stored procedure to do some combined keyword search using
I have written below stored procedure. In which i need to create Two Temporary
I have a stored procedure mentioned as below. I'm using SQL Server 2008 R2.

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.