Otshepeng Ditshego
Otshepeng Ditshego

Reputation: 197

Change single value using CASE statement

I have records that look like:

GCR,
ER, 
SR,
WR,
NER
CR

I want to change the GCR to GC using a case statement on my view while also showing the other values. How can I do it?

Upvotes: 0

Views: 2099

Answers (3)

Mansoor
Mansoor

Reputation: 4192

Use below query :

SELECT CASE WHEN ColumnName = 'GCR' THEN 'CR' ELSE ColumnName END 
FROM your_table  

Upvotes: 2

Gordon Linoff
Gordon Linoff

Reputation: 1271151

You use case with else:

select (case when col = 'GCR' then 'CR' else col end) as new_col

If you need to do this repeatedly, you can add a computed column with the expression:

alter t add new_col as (case when col = 'GCR' then 'CR' else col end);

Then, any query can use new_col and it would be calculated correctly (on the fly).

Upvotes: 0

SynozeN Technologies
SynozeN Technologies

Reputation: 1347

try this.

select case when YourColumnName= 'a123' then 'CR' end 'ColumnName' from YourTableName

Upvotes: 0

Related Questions