Tsql 在SQL中将两个列串联在一个列中
我有两列,其中一列是外来ID,如何将它们连接成一列 例如:Tsql 在SQL中将两个列串联在一个列中,tsql,sql-server-2008-r2,Tsql,Sql Server 2008 R2,我有两列,其中一列是外来ID,如何将它们连接成一列 例如: StateID = 1 Area = "Bronx" 成为: New York - Bronx 编辑: 使用+连接列: 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 us
StateID = 1
Area = "Bronx"
成为:
New York - Bronx
编辑:
使用
+
连接列:
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 )
您的表名是什么?查找表的格式是什么?而
StateID
是Address.ID
的外键?
SELECT StateID + ' - ' + Area AS SateArea
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 )