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 2008 Forums
 Transact-SQL (2008)
 Translation in SELECT statement

Author  Topic 

babloo
Starting Member

35 Posts

Posted - 2012-12-13 : 10:11:02
Hi, I have some fields that I am trying to use in my Query. Is there a way I could do some kinda translation when I get my output such as:


Select v_facility_code as [Facility],

The values are 123 and abc, when I get 123 I want output to show Facility1, abc for Facility2.

Same case for visit_admit_source as [Admit Source]

Values are 2 digit alphabets, ex. NB, I want that to be translated to NewBorn

Thanks alot.

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-12-13 : 10:14:13
select case v_facility_code when '123' then 'Facility1' when 'abc' then 'Facility2' else v_facility_code end
from ...

Would be better if these values were in a table then you could join to it.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

babloo
Starting Member

35 Posts

Posted - 2012-12-13 : 10:22:26
Thanks Nigelrivett. These values are already in a table.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-12-14 : 03:12:40
do a join like

SELECT columns...,m.Description,m1.Description,..
FROM table t
JOIN MappingTable m
ON m.ID = v_facility_code
JOIN MappingTable m1
ON m1.ID = visit_admit_source
...


i've assumed column names so make sure you use actual columns inside

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -