• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how I can swap content of two fields in one table?

 
raminaa niilian
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Is there an easy way to swap content of two fields (sn and ssn) in a table with hundreds of rows?
I insert the content of those field by mistake. all sn values are stored under ssn and all ssn values are stored under sn.
Thanks
 
Jan Cumps
Bartender
Posts: 2608
14
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try:

 
Himanshu Kansal
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if the above works, it is simply wonderful. In case it does not just think of your problem as that you want to rename the columns
 
Jan Cumps
Bartender
Posts: 2608
14
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Himanshu Kansal wrote:if the above works, it is simply wonderful.
It is, isn't it?

It works because your database will first resolve the value of sn and snn , before writing the new values.
just the same as update a_table set x = x + 1 increments column x. It reads the value of column x, increments it with 1, then writes that value to column x.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic