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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 alias

Author  Topic 

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2008-04-21 : 14:22:26
I want an alias instead of display the column name for the below query..

select STE = case when STE ='AT' then '01'
when STE = 'AT1' then '02'
......
.......
.......
........
else STE
end
from tableinfo

Output for the query

STE
---
01
02

Desired output:

STEDN
-----
01
02

Thanks for the help in advance !!!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-04-21 : 14:27:45
SELECT STEDN = case when STE = 'AT' then '01'...

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-21 : 14:35:49
or:-

select case when STE ='AT' then '01'
when STE = 'AT1' then '02'
......
.......
.......
........
else STE
end AS STEDN
from tableinfo
Go to Top of Page

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2008-04-21 : 16:44:26
Thanks Tara Kizer it works.
But visakh16 with your query its gives an error

Incorrect syntax near the keyword 'as'.


Go to Top of Page

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2008-04-21 : 17:10:12
Sorry visakh16!!
Your query also worked fine..
Go to Top of Page
   

- Advertisement -