Generate UserNames | Database Journal

Generate UserNames

Nov 30, 2009
1 minute read

>>Script Language and Platform: SQL Server
This udf_SuggestUserName function generates usernames based on date of birth, zipcode, username, firstname and lastname. It also generates zodiac username based on date of birth.

Useful in suggesting a list of usernames to the person who is trying to register and if the username already exist in the database.

Usage:

select * from dbo.udf_SuggestUserName
   (‘Kurara’,’Chibana’,’03-12-1982′,’07051′,’RainbowRiver’)
–result
Chibana_07051
Chibana_Kurara
Chibana_Pisces_Chibana
Chibana19820312
Chibana82
ChibanaKurara
contact_Chibana
contact_Kurara
contact_RainbowRiver
contactChibana
contactKurara
contactRainbowRiver
KChibana
KChibana1982
KChibana82
Kurara_07051
Kurara_Chibana
Kurara_numberone
Kurara_Pisces_Kurara
Kurara19820312
Kurara82
KuraraChibana
Message_RainbowRiver
Pisces_Chibana
Pisces_Kurara
Pisces07051
Pisces19820312
RainbowRiver_07051
RainbowRiver_1
RainbowRiver_1982
RainbowRiver_2
RainbowRiver_3
RainbowRiver_4
RainbowRiver_5
RainbowRiver_6
RainbowRiver_7
RainbowRiver_8
RainbowRiver_9
RainbowRiver1
RainbowRiver1982
RainbowRiver19820312
RainbowRiver2
RainbowRiver3
RainbowRiver4
RainbowRiver5
RainbowRiver6
RainbowRiver7
RainbowRiver8
RainbowRiver82
RainbowRiver9
reach_Chibana
reach_Kurara
reach_RainbowRiver
reachChibana
reachKurara
reachRainbowRiver

Author: MAK


if exists (select * from dbo.sysobjects
  where id = object_id(N’[dbo].[udf_SuggestUserName]’)
  and xtype in (N’FN’, N’IF’, N’TF’))
drop function [dbo].[udf_SuggestUserName]
GO
Create function dbo.udf_SuggestUserName
(@firstname varchar(100),
@lastname varchar(100),
@dob datetime,
@zipcode varchar(12),
@username varchar(100))
returns @usernameTable TABLE (username varchar(100))
as
begin
declare @year2 int
declare @zodiac varchar(15)
declare @dob2 datetime
set @dob2= convert
  (datetime,convert(varchar(2),month(@dob))+-+convert(varchar(2),day(@dob))+-2000′ )
select @zodiac = case
when @dob2 between3/21/2000and4/20/2000then ‘Aries’
when @dob2 between4/21/2000and5/21/2000then ‘Taurus’
when @dob2 between5/22/2000and6/22/2000then ‘Gemini’
when @dob2 between6/23/2000and7/23/2000then ‘Cancer’
when @dob2 between7/24/2000and8/23/2000then ‘Leo’
when @dob2 between8/24/2000and9/23/2000then ‘Virgo’
when @dob2 between9/24/2000and10/23/2000then ‘Libra’
when @dob2 between10/24/2000and11/22/2000then ‘Scorpio’
when @dob2 between11/23/2000and12/22/2000then ‘Sagittarius’
when @dob2 between12/23/2000and1/19/2000then ‘Capricorn’
when @dob2 between1/20/2000and2/19/2000then ‘Aquarius’
when @dob2 between2/20/2000and3/20/2000then ‘Pisces’ end
insert into @usernameTable
select @firstname+’_’+@lastname union
select @lastname+’_’+@firstname union
select @firstname+@lastname union
select @lastname+@firstname union
select left(@firstname,1)+@lastname union
select @username+’_’+@zipcode union
select ‘reach’+’_’+@username union
select ‘contact’+’_’+@username union
select ‘reach’+’_’+@firstname union
select ‘contact’+’_’+@lastname union
select ‘reach’+’_’+@lastname union
select ‘contact’+’_’+@firstname union
select ‘reach’+@username union
select ‘contact’+@username union
select ‘reach’+@firstname union
select ‘contact’+@lastname union
select ‘reach’+@lastname union
select ‘contact’+@firstname union
select left(@firstname,1)+@lastname+convert(varchar(4),year(@dob)) union
select @username+’_’+convert(varchar(4),year(@dob)) union
select @username+convert(varchar(4),year(@dob)) union
select @firstname+’_’+@zipcode union
select @lastname+’_’+@zipcode union
select ‘Message_’+@username union
select @username+convert(varchar(8),@dob,112) union
select @Firstname+convert(varchar(8),@dob,112) union
select @Lastname+convert(varchar(8),@dob,112) union
select @Firstname+’_numberone’ union
select @username+’_1′ union
select @username+’_2′ union
select @username+’_3′ union
select @username+’_4′ union
select @username+’_5′ union
select @username+’_6′ union
select @username+’_7′ union
select @username+’_8′ union
select @username+’_9′ union
select @username+1union
select @username+2union
select @username+3union
select @username+4union
select @username+5union
select @username+6union
select @username+7union
select @username+8union
select @username+9union
select @zodiac+convert(varchar(8),@dob,112) union
select @zodiac+@zipcode union
select @zodiac+’_’+@firstname union
select @zodiac+’_’+@lastname union
select @firstname+’_’+@zodiac+’_’+@firstname union
select @lastname+’_’+@zodiac+’_’+@lastname union
select @firstname+right(convert(varchar(4),year(@dob)),2) union
select @lastname+right(convert(varchar(4),year(@dob)),2) union
select @username+right(convert(varchar(4),year(@dob)),2) union
select left(@firstname,1)+@lastname+right(convert(varchar(4),year(@dob)),2)
RETURN
end
go



Disclaimer:
We hope that the information on these script pages is
valuable to you. Your use of the information contained in these pages,
however, is at your sole risk. All information on these pages is provided
“as -is”, without any warranty, whether express or implied, of its accuracy,
completeness, or fitness for a particular purpose…

Disclaimer Continued

Back to Database Journal Home

Database Journal Logo

DatabaseJournal.com publishes relevant, up-to-date and pragmatic articles on the use of database hardware and management tools and serves as a forum for professional knowledge about proprietary, open source and cloud-based databases--foundational technology for all IT systems. We publish insightful articles about new products, best practices and trends; readers help each other out on various database questions and problems. Database management systems (DBMS) and database security processes are also key areas of focus at DatabaseJournal.com.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.