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
 Replace code with words

Author  Topic 

ugh3012
Yak Posting Veteran

62 Posts

Posted - 2012-06-20 : 15:58:06

I have a SQL statement that looks something like this.

Select ID, code, name
From table
where .....

The field name code is a one char field. Is it possible for MS SQL to replace one letter code with the actual code name in the result set. There is no other table for me to inner join to get the code name, so that part is out as there are only 4 different possible codes.

for example:
instead of retuning - 2403 N Apple
it would return - 2403 New Apple

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-06-20 : 16:04:39
select
ID,
case
when code = 'N' then 'New'
when code = 'O' then 'Old'
end as code,
name
from table


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -