Reputation: 2985
I'm trying to rename a column name in order to aid mapping data from this database into another for a data push.
What I need to do is change the name of StdType
to IncomeType
, although no matter what I try it simply does not change the column name in the result.
This is my SQL query:
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
is a temporary table which does exist and works for my other queries.
Finstat_Income
is a table and not a view. I've also tried the query with and without square brackets but there is no difference.
The resulting output is headed as:
AAID | Description | Amount | Note | StdType
Where my desired output is:
AAID | Description | Amount | Note | IncomeType
Upvotes: 0
Views: 64
Reputation: 15061
Put your alias next to the column name.
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
Upvotes: 1
Reputation: 10843
You are Aliasing the table, not the column. Try this -
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
Upvotes: 4
Reputation: 1913
Perhaps this
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
Upvotes: 0