Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Renaming a colum for reporting?

Author  Topic 

louiedogg418
Starting Member

28 Posts

Posted - 2011-04-22 : 12:23:58
What is the statement that changes the name of a column jsut for reporting but does not change the column name for good?
I.e. 'Emp_sal' to 'Salary'?

is it an AS statemnt? and how is this used?
Thank you!

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-04-22 : 12:27:16
SELECT Emp_Sal as 'Salary'
FROM yourTable. It doesn't change anything in the table, just the display name in the result set.

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

louiedogg418
Starting Member

28 Posts

Posted - 2011-04-23 : 11:42:33
select avg(sal) from employee as Average

query works but still isnt changing the name.... if i put single quotes around average i get error 102
Go to Top of Page

jeffw8713
Aged Yak Warrior

819 Posts

Posted - 2011-04-23 : 12:55:06
In your query, you aliased the table - not the column. Your query should be:

SELECT avg(t.sal) AS Salary FROM dbo.Employee AS t

In this query, I have aliased the table as 't' and aliased the column as Salary.

Jeff
Go to Top of Page
   

- Advertisement -