我正在尝试重命名列名,以帮助将数据库中的数据映射到另一个数据库以进行数据推送。
我需要做的是将StdType
的名称更改为IncomeType
,但无论我尝试什么,它都不会更改结果中的列名。
这是我的SQL查询:
SELECT
'AA' + CAST(ClientID AS VARCHAR) AS AAID,
Description,
Convert(Money,Amount)/100 AS Amount,
Note,
StdType FROM [Finstat_Income] AS IncomeType
INNER JOIN #Assessments A
ON 'AA' + CAST(ClientID AS VARCHAR) = A.AAID
#Assessments
是一个临时表,它确实存在并适用于我的其他查询。
Finstat_Income
是一个表而不是视图。我也尝试过使用和不使用方括号的查询,但没有区别。
结果输出为:
AAID | Description | Amount | Note | StdType
我想要的输出是:
AAID | Description | Amount | Note | IncomeType
答案 0 :(得分:4)
您正在对表进行别名,而不是列。试试这个 -
SELECT
'AA' + CAST(ClientID AS VARCHAR) AS AAID,
Description,
Convert(Money,Amount)/100 as Amount,
Note,
StdType AS IncomeType
FROM [Finstat_Income]
INNER JOIN #Assessments A
ON 'AA' + CAST(ClientID AS VARCHAR) = A.AAID
答案 1 :(得分:1)
将别名放在列名旁边。
SELECT
'AA' + CAST(ClientID AS VARCHAR) AS AAID,
Description,
Convert(Money,Amount)/100 AS Amount,
Note,
StdType AS IncomeType
FROM [Finstat_Income]
INNER JOIN #Assessments A ON 'AA' + CAST(ClientID AS VARCHAR) = A.AAID
答案 2 :(得分:0)
也许这个
SELECT
'AA' + CAST(ClientID AS VARCHAR) AS AAID,
Description,
Convert(Money,Amount)/100 as Amount,
Note,
StdType as [IncomeType] FROM [Finstat_Income] AS IncomeType
INNER JOIN #Assessments A
ON 'AA' + CAST(ClientID AS VARCHAR) = A.AAID