Advertisement
anchormodeling

Random Name Generator

Feb 7th, 2018
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 2.76 KB | None | 0 0
  1. declare @consonantName varchar(42);
  2. declare @vowelName varchar(42);
  3.  
  4. with vowels as (
  5.     select
  6.         *
  7.     from (
  8.         values
  9.         ('a'),('e'),('i'),('o'),('u'),('y'),
  10.         (null)
  11.     ) v (vowel)
  12. ),
  13. consonants as (
  14.     select
  15.         *
  16.     from (
  17.         values
  18.         ('b'),('c'),('d'),('f'),('g'),('h'),
  19.         ('j'),('k'),('l'),('m'),('n'),('p'),
  20.         ('q'),('r'),('s'),('t'),('v'),('w'),
  21.         ('x'),('z'),
  22.         (null)
  23.     ) c (consonant)
  24. ),
  25. names as (
  26.     select
  27.         upper(isnull((select top 1 consonant from consonants where consonant is not null order by newid()), '')) +
  28.         isnull((select top 1 vowel from vowels order by newid()), '') +
  29.         isnull((select top 1 consonant from consonants order by newid()), '') +
  30.         isnull((select top 1 vowel from vowels order by newid()), '') +
  31.         isnull((select top 1 consonant from consonants order by newid()), '') +
  32.         isnull((select top 1 vowel from vowels order by newid()), '') +
  33.         isnull((select top 1 consonant from consonants order by newid()), '') +
  34.         isnull((select top 1 vowel from vowels order by newid()), '') +
  35.         isnull((select top 1 consonant from consonants order by newid()), '') +
  36.         isnull((select top 1 vowel from vowels order by newid()), '') +
  37.         isnull((select top 1 consonant from consonants order by newid()), '') +
  38.         isnull((select top 1 vowel from vowels order by newid()), '') +
  39.         isnull((select top 1 consonant from consonants order by newid()), '') +
  40.         isnull((select top 1 vowel from vowels order by newid()), '') as consonantName,
  41.         upper(isnull((select top 1 vowel from vowels where vowel is not null order by newid()), '')) +
  42.         isnull((select top 1 consonant from consonants order by newid()), '') +
  43.         isnull((select top 1 vowel from vowels order by newid()), '') +
  44.         isnull((select top 1 consonant from consonants order by newid()), '') +
  45.         isnull((select top 1 vowel from vowels order by newid()), '') +
  46.         isnull((select top 1 consonant from consonants order by newid()), '') +
  47.         isnull((select top 1 vowel from vowels order by newid()), '') +
  48.         isnull((select top 1 consonant from consonants order by newid()), '') +
  49.         isnull((select top 1 vowel from vowels order by newid()), '') +
  50.         isnull((select top 1 consonant from consonants order by newid()), '') +
  51.         isnull((select top 1 vowel from vowels order by newid()), '') +
  52.         isnull((select top 1 consonant from consonants order by newid()), '') +
  53.         isnull((select top 1 vowel from vowels order by newid()), '') +
  54.         isnull((select top 1 consonant from consonants order by newid()), '') as vowelName
  55. )
  56. select
  57.     @consonantName = (select top 1 consonantName from names),
  58.     @vowelName = (select top 1 vowelName from names)
  59.  
  60. select
  61.     case
  62.         when rand(checksum(newid())) > 0.5
  63.         then left(@consonantName, 2 + rand(checksum(newid())) * 12)
  64.         else left(@vowelName, 2 + rand(checksum(newid())) * 12)
  65.     end as [name]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement