我有两列,其中有一个外国ID,如何将它们连接成一列?
示例:
StateID = 1
Area = "Bronx"
成为:
New York - Bronx
编辑:
Table1 = [Address] has two columns, (ID, Name)
Table2 = [Requests] has many columns including (Area, StateID)
答案 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 )
答案 1 :(得分:0)
SELECT StateID + ' - ' + Area AS SateArea