Click here to Skip to main content
15,914,500 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi is it possible to swap two columns of SQL without using Update Statement? My Table structure is as below.

sno A B C
1 2 3 1
2 Y Z X
3 Night Noon Day
4 Moon Mars Sun
5 100 200 50

Now i want to swap a to b, b to c and c to a.

How can i perform this without using update statement.
Posted

1 solution

Select into temp table in new order, truncate original table, drop temp table.

SQL
select sno, c as a, a as b, b as c into #mytemptable from mytable
truncate table mytable
insert into mytable select * from #mytemptable
drop table #mytemptable


Hope this helps,
Fredrik
 
Share this answer
 
Comments
ARUN K P 3-Sep-13 7:53am    
Yep it s working. thanks.
Fredrik Bornander 3-Sep-13 8:18am    
Glad I could help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900