在SQL中将两列连接在一起

时间:2013-09-11 15:28:20

标签: tsql sql-server-2008-r2

我有两列,其中有一个外国ID,如何将它们连接成一列?

示例:

StateID = 1
Area = "Bronx"

成为:

New York - Bronx

编辑:

Table1 = [Address] has two columns, (ID, Name)
Table2 = [Requests] has many columns including (Area, StateID)

2 个答案:

答案 0 :(得分:1)

使用+连接列:

SELECT a.Name + ' - ' + r.Area As StateAndArea
FROM dbo.Requests r INNER JOIN dbo.Address a
    ON r.StateID = a.ID
ORDER BY StateAndArea -- ( alias can be used in order by but not in where )

+ (String Concatenation)

答案 1 :(得分:0)

SELECT StateID + ' - ' + Area AS SateArea