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
 Need Function

Author  Topic 

rajadadi
Starting Member

30 Posts

Posted - 2010-05-03 : 04:50:18
Actually database store Value is 2 but in front end it shows : Inservice

but i want to take report so i need function to convert that value to this string.

these are the value 0,1,2,3

these are front end value: Out of Service,Inservice,Hold,N/A

please tell me the function to convert this

rajesh

karthik_padbanaban
Constraint Violating Yak Guru

263 Posts

Posted - 2010-05-03 : 04:55:11

select case when column_name = 0 then 'Out of Service'
when column_name = 1 then 'Inservice'
when column_name = 2 then 'Hold'
when column_name = 3 then 'N/A' end as [Column_name]
from table_name



Karthik
http://karthik4identity.blogspot.com/
Go to Top of Page

DBA in the making
Aged Yak Warrior

638 Posts

Posted - 2010-05-03 : 08:27:47
You should have a lookup table, with the following values. Then join to that table.
0 Out of Service
1 Inservice
2 Hold
3 N/A

These items (Out of Service, Inservice, Hold, N/A) are data. Data is stored in tables, not in functions, queries, stored procs, etc.

------------------------------------------------------------------------------------
Any and all code contained within this post comes with a 100% money back guarantee.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-05-03 : 09:46:56
i would also second last suggestion as it gives you flexibility of adding new items as well as there mapping values without touching you code. Any addition would simply mean a new insert to lookup table rather than tweakung your code with CASE

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

Go to Top of Page
   

- Advertisement -