在不使用Update Statement的情况下交换sql中的列。 [英] Swapping the columns in sql without using Update Statement.
本文介绍了在不使用Update Statement的情况下交换sql中的列。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您可以在不使用Update Statement的情况下交换两列SQL吗?我的表格结构如下。
sno A B C
1 2 3 1
2 Y Z X
3晚中午
4月亮火星太阳
5 100 200 50
现在我想要交换a到b,b到c和c到a。
如何在不使用update语句的情况下执行此操作。
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.
推荐答案
按新顺序选择临时表,截断原始表,删除临时表。
Select into temp table in new order, truncate original table, drop temp table.
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
希望这会有所帮助,
Fredrik
Hope this helps,
Fredrik
这篇关于在不使用Update Statement的情况下交换sql中的列。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文