SQL Server - swap or update 1st column value into 2nd column values
Asked By myzonal.com myzonal.com on 01-Aug-13 09:59 AM
Hi All,
I have a table with data like something as -
id1 id2
1 5
2 8
3 6
Output like -
id1 id2
5 1
8 2
6 3
I want to swap value all values of 1st column in 2nd column and 2 columns value into 1st column.
Robbe Morris replied to myzonal.com myzonal.com on 01-Aug-13 09:58 AM
Put up a test table and try this against test data
update mytable
set cola = colB,
colb = cola
where some key = blah
I "think" this should work because the commit on the transaction should not happen after the set cola = colb, it should happen after everything is done.