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 884865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:48:50+00:00 2026-05-15T12:48:50+00:00

How to create or what is the logic of function which Generate names for

  • 0

How to create or what is the logic of
function which
Generate names for non registered users
using given name as string variable
using sql 2005
(like registering in hotmail ,yahoo)

  • 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-15T12:48:51+00:00Added an answer on May 15, 2026 at 12:48 pm

    Are you trying to generate a unique username for a ‘user’ record, given their real name? Or email address? Is this so they can be tracked/stored in SQL Server (your question is not very clear)? The usual thing would be not to create a username for them (that’s one of the advantages you can use to entice the user to sign up, they get their own username).

    Instead you could use the email address itself as the primary key, which will always be unique anyway: the username field would be nullable (allow NULLs), and only contain data if the user has signed up and picked a name.

    If you wanted to display a username, or their email address if they don’t have a username, you could use COALESCE or ISNULL, for example SELECT ISNULL(username, email_address) – which gives the value of ‘username’, unless it is null, in which case it gives the value of ’email_address’.

    Hope that helps – perhaps not the question you were asking but if you could rephrase or elaborate then we will be happy to help further.


    Alternatively, I read your question again: are you trying to suggest usernames that are available, to the user? For example, if they enter:

    First Name: Kieren
    Last Name: Johnstone

    Then you want to suggest KierenJohnstone, KierenJohnstone1, JohnstoneK, KJohnstone etc? (if they are available, that is).

    If that is the case, you should write a method which generates possibilities, like this:

    public IEnumerable<string> GeneratePossibleBaseUsernames(string firstname, string lastname)
    {
        yield return firstname + lastname; // eg KierenJohnstone
        yield return lastname + firstname; // eg JohnstoneKieren
        yield return firstname.Substring(0,1) + lastname; // eg KJohnstone
        yield return lastname + firstname.Substring(0,1); // eg JohnstoneK
        yield return firstname + lastname.Substring(0,1); // eg KierenJ
    }
    

    Then, you would see if those are available in the database:

    public List<string> GetAvailablePossibleUsernames(string firstname, string lastname)
    {
        List<string> availablePossibilities = new List<string>();
    
        foreach (string possible in GeneratePossibleBaseUsernames(firstname, lastname))
        {
            if (IsAvailable(possible))
            {
                availablePossibilities.Add(possible);
                continue;
            }
            for (int i = 1; i < 100; i++)
            {
                string postfixedTest = possible + i.ToString();
                if (IsAvailable(postfixedTest))
                {
                    availablePossibilities.Add(postfixedTest);
                    break;
                }
            }
        }
        return availablePossibilities;
    }
    

    You would need to write the IsAvailable() method, to take a string as a parameter and return a bool – ‘true’ if the username doesn’t already exist in the database.

    This method will return a List of string objects, with suggestions: it will try the results from GeneratePossibleBaseUsernames, and if one of them isn’t available then it will try it with numbers 1 through 99 after it, e.g. if KierenJohnstone was taken it would suggest KierenJohnstone1.

    You could also implement all of this within a SQL Stored Procedure. You will definitely want to double-check the name is available when you are inserting/update the record, or put a unique index on the username table to stop duplicates – in case two people use the same name as the same time!

    Hope that helps.

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

Sidebar

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.