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.
| Author |
Topic |
|
Maverick_
Posting Yak Master
107 Posts |
Posted - 2010-11-08 : 06:24:29
|
| Hi allI have a table that contains 10,000+ jobs, each job has an overall status represented by a bunch of "internal" codes, rather than appear as codes these need to be translated into proper terms for readers to understand when viewing a list of results. Example:J001J002J003All the above need to be appear as 'Work done'.E0100E0200E0300These to appear as 'Work not done'...Does anyone know how I could show the proper definitions rather than the code name for each job result? I tried applying the REPLACE statement but it did not work.Unfortunately I can only "Read" data and can't alter the table to add a new column for names. |
|
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2010-11-08 : 06:31:49
|
| Like this maybe? ->SELECT Status = CASE WHEN LEFT(Column, 1) = 'J' THEN 'Work done' ELSE 'Work not done' ENDFROM table- LumbagoMy blog (yes, I have a blog now! just not that much content yet) -> www.thefirstsql.com |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-11-08 : 06:32:17
|
| [code]declare @t table(Code varchar(50))insert @tselect 'J001' unionselect 'J002' unionselect 'J003'unionselect 'E0100' unionselect 'E0200' unionselect 'E0300'select case when nullif(LEFT(Code,1),'J')is null then 'Work done' else 'Work not done'end code from @t[/code]PBUH |
 |
|
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2010-11-08 : 07:32:10
|
| What's the point of the NULLIF?- LumbagoMy blog (yes, I have a blog now! just not that much content yet) -> www.thefirstsql.com |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-11-08 : 07:35:12
|
quote: Originally posted by Lumbago What's the point of the NULLIF?- LumbagoMy blog (yes, I have a blog now! just not that much content yet) -> www.thefirstsql.com
Nothing.Just a different way of doing it.PBUH |
 |
|
|
|
|
|