August 15, 2008 at 3:24 pm
I have a situation where I am joining multiple tables together (SQL Server 2005 - Standard Edition). Some of the tables have similar field names.
I’d like to display those field names as different field names (change “description”, to “Offense_Description”, etc).
I also want to dump this data in a temp table and keep those field name changes.
Can this be done?
Thank you very much for your response.
August 15, 2008 at 8:43 pm
Yes, this can be done using an alias. Example:
SELECT t1.col1 AS t1_col1
,t1.col2 AS t1_col2
,t2.col1 AS t2_col1
,t2.col2 AS t2_col2
FROM table1 AS t1
INNER JOIN table2 AS t2 ON t2.key = t1.key
In the above query, I am aliasing table1 as t1, table2 as t2, table1 col1 as t1_col1, etc...
Jeffrey Williams
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs
August 16, 2008 at 3:51 pm
And, yes, it's easy to dump that into a temp table...
Yes, this can be done using an alias. Example:
SELECT t1.col1 AS t1_col1,
t1.col2 AS t1_col2,
t2.col1 AS t2_col1,
t2.col2 AS t2_col2
INTO #somenewtemptable
FROM table1 AS t1
INNER JOIN table2 AS t2 ON t2.key = t1.key
--Jeff Moden
Change is inevitable... Change for the better is not.
August 16, 2008 at 3:56 pm
Oops - forgot the temp table, thanks Jeff.
Jeffrey Williams
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs
August 16, 2008 at 8:00 pm
Jeffrey Williams (8/16/2008)
Oops - forgot the temp table, thanks Jeff.
No problem... it's the beauty of a forum... world's biggest team. 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
August 18, 2008 at 7:08 am
Thanks Jeff & Jeffrey!!!
August 18, 2008 at 5:55 pm
You bet... thank you for the feedback.../ 🙂
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 7 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply