Skip to content

Instantly share code, notes, and snippets.

@jbnv
Created June 2, 2015 00:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbnv/57fbdce6d0394962942c to your computer and use it in GitHub Desktop.
Save jbnv/57fbdce6d0394962942c to your computer and use it in GitHub Desktop.
Query to generate a number of English names for data mocking
/*
The referenced views (which could also be tables) are one-column views
(or tables) that contain instances of the particular type of name. For
[EnglishMaleFirstNameView] and [EnglishFemaleFirstNameView], the one
column must be named [Name]. For [EnglishSurnamePrefixView], the one
column must be named [Prefix]. This view can contain surnames that would
otherwise stand alone. For [EnglishSurnameSufffixView], the one column
must be named [Suffix]. Each element of this list must not be
capitalized. This list should contain an empty string element so that
the prefix can stand alone. Examples of each of these views are
elsewhere in this repository.
*/
SELECT
ROW_NUMBER() OVER (ORDER BY pre.[Prefix],suf.[Suffix],firstNames.[FirstName]) AS [Ordinal],
firstNames.[Gender],
firstNames.[FirstName],
pre.[Prefix]+suf.[Suffix] AS [Surname]
FROM (
SELECT [Name] AS [FirstName],'m' AS [Gender] FROM [EnglishMaleFirstNameView]
UNION
SELECT [Name] AS [FirstName],'f' AS [Gender] FROM [EnglishFemaleFirstNameView]
) firstNames
CROSS JOIN (
SELECT [Name] AS [Prefix] FROM [EnglishMaleFirstNameView]
UNION
SELECT [Name] AS [Prefix] FROM [EnglishFemaleFirstNameView]
UNION
SELECT [Prefix] FROM [EnglishSurnamePrefixView]
) pre
CROSS JOIN [EnglishSurnameSuffixView] suf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment