This query is actually a lot simpler than it first appears. Here’s how it breaks down:
Pick 100 words at random (table “a”)
For each word in “a”, if possible, pick a single random word (“b”) that doesn’t start or end with the same three letters as the “a” word.
For each word in “b”, if possible, pick a single random word (“c”) that doesn’t start or end with the same three letters as the “a” nor the “b” word.
The UPPER(), LEFT() and SUBSTRING() stuff is just to turn the names into title case.
As before, the ORDER BY NEWID() randomizes the order in which the TOP (1) row is returned.
My favorite name when running this was Disaster Votes, followed closely by Fail Users Vendor and Terminated Enterprise. Apparently my SQL Server instance has a very negative impression of my made up companies’ leadership skills.