如何加入两个SQL查询?

时间:2012-11-08 14:16:55

标签: sql tsql sql-server-2012

将两个SQL查询放入同一个表中

SELECT FirstName,
       LastName,
       LEFT(FirstName, 1) + '.' + LEFT(LastName, 1) AS Initial
FROM   ContactUpdates

输出:

FirstName    LastName    Initial

我想在初始结束

的右侧加入另一个
SELECT LOWER(LEFT(FirstName, 1) + REPLACE(LastName,'''','' ) )
         + '@email.com' AS Email
FROM   ContactUpdates

最后我希望它是

 FirstName    LastName    Initial    Email 

但我无法弄清楚如何让他们加入任何帮助?

2 个答案:

答案 0 :(得分:2)

SELECT FirstName, 
    LastName, 
    LEFT(FirstName,1) + '.' + LEFT(LastName,1) AS Initial, 
    LOWER(LEFT(FirstName, 1) + REPLACE(LastName, '''', '')) + '@email.com' AS Email
FROM ContactUpdates

答案 1 :(得分:2)

然后只需将该列附加到查询中:

SELECT FirstName
     , LastName
     , LEFT(FirstName,1) + '.' + LEFT(LastName,1) AS Initial 
     , LOWER(LEFT(FirstName,1) + REPLACE(LastName,'''','' ) ) + '@email.com' AS Email
FROM ContactUpdates