SQL : swap 2 values in a column without using an intermediate value

0

Given a table with a single column containing only 2 values, say 'A' and 'B', is there a way to swap them in a single statement

Ex:

A
B
A
B

to

B
A
B
A

It is a trivial process if we use a bit or a placeholder value, (Change all A to C, all B to A, all C to B), but is there a generalized method to do this?

Akash

Posted 2013-12-06T07:21:03.640

Reputation: 3 682

Answers

0

Alright, so a statement like this works:

update tab set col=IIF(col='A','B','A')

I'll leave this up incase people have better approaches, unless there are requests to delete it

Akash

Posted 2013-12-06T07:21:03.640

Reputation: 3 682