Reputation: 1
I just came across a scenario i.e there is table BATCH with 10 records with column sl_no and batch_typ like below.
Here I want to update the Batch_typ where BLUE it should be green and vice versa with SQL query.Thanks in advance.
Upvotes: 0
Views: 44
Reputation: 56
You can use update with Case for this kind of scenarios
UPDATE BATCH set batch_typ =
case when batch_typ = 'BLUE' then 'GREEN'
when batch_typ = 'GREEN' then 'BLUE' end;
````````````````
Upvotes: 0
Reputation: 5141
Please use below update statement,
update BATCH set batch_typ =
case when batch_typ = 'BLUE' then 'GREEN'
when batch_typ = 'GREEN' then 'BLUE' end;
Upvotes: 0
Reputation: 520958
You may update using a CASE
expression:
UPDATE BATCH
SET BATCH_TYP = CASE WHEN BATCH_TYP = 'GREEN' THEN 'BLUE' ELSE 'GREEN' END
WHERE BATCH_TYP IN ('GREEN', 'BLUE');
Upvotes: 1