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
 How to rename output to something else?

Author  Topic 

Maverick_
Posting Yak Master

107 Posts

Posted - 2010-11-08 : 06:24:29
Hi all

I 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:

J001
J002
J003

All the above need to be appear as 'Work done'.

E0100
E0200
E0300

These 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' END
FROM table


- Lumbago

My blog (yes, I have a blog now! just not that much content yet)
-> www.thefirstsql.com
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-11-08 : 06:32:17
[code]
declare @t table(Code varchar(50))
insert @t
select 'J001' union
select 'J002' union
select 'J003'union
select 'E0100' union
select 'E0200' union
select 'E0300'



select case when nullif(LEFT(Code,1),'J')is null then 'Work done' else 'Work not done'
end code from @t


[/code]

PBUH

Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2010-11-08 : 07:32:10
What's the point of the NULLIF?

- Lumbago

My blog (yes, I have a blog now! just not that much content yet)
-> www.thefirstsql.com
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-11-08 : 07:35:12
quote:
Originally posted by Lumbago

What's the point of the NULLIF?

- Lumbago

My 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

Go to Top of Page
   

- Advertisement -