Reputation: 1
i have a table like below
empid empname grade
1 rr A
2 raju B
3 lokesh A
4 sathish B
i want repalce the A by B and B by A in above table using single update statement can any one suggest a good answer in sql..
Upvotes: 0
Views: 62
Reputation: 4314
Try this query
Update table
set grade = CASE
WHEN grade = 'A' THEN 'B'
WHEN grade = 'B' THEN 'A'
END
WHERE grade IN ('A', 'B')
Upvotes: 0
Reputation: 204784
update your_table
set grade = case when grade = 'A' then 'B'
when grade = 'B' then 'A'
end
where grade in ('A','B')
Upvotes: 2