我试图创建一个简单的查询,选择一个随机的名称和姓氏,并将其插入结果表。我想创建一些我可以与操作大量数据的测试交换的东西。这是一个代码(为了简单起见,我只包括五个名字和姓氏):* L9 \' q; I3 O- l" \% i3 O
SELECT FirstName,LastNameFROM (SELECT TOP FirstName FROM (SELECT 'John' AS FirstName UNION SELECT 'Tim' AS FirstName UNION SELECT 'Laura' AS FirstName UNION SELECT 'Jeff' AS FirstName UNION SELECT 'Sara' AS FirstName) AS First_Names ORDER BY NEWID()) n1FULL OUTER JOIN (SELECT TOP LastName FROM (SELECT 'Johnson' AS LastName UNION SELECT 'Hudson' AS LastName UNION SELECT 'Jackson' AS LastName UNION SELECT 'Ranallo' AS LastName UNION SELECT 'Curry' AS LastName) AS Last_Names ORDER BY NEWID()) n2 ON [n1].FirstName = [n2].LastNameWHERE n1.FirstName IS NOT NULL OR n2.LastName IS NOT NULL结果如下:) q5 r2 J+ }, ]$ c9 w" k' x
FirstName LastName NULL HudsonJohn NULL希望结果回到一行,随机生成一个名字和姓氏,让每行都有一个完整的名字(没有)NULL值)。我敢肯定,这是我忽略的一件简单的事情。 7 }& n1 n8 o3 x% S0 V! D # z `/ f# H) w 解决方案: