Share via


Swap

The 101 class of programming makes you write a program to swap two numbers. It is during this excercise it hits most of us, that we need to think like machines. Hence evolves the implementation: Move the first variable value into a temp variable, move the second variable value into the first one and finally the temp variable value into the second variable. The learning, atleast for me, then was that computers can't think like us; we need to ensure that we give them each little step; steps that our brain cells carry on involuntarily; it already memorized the value in the first variable before swapping them, which I had to explicitly specify it to do.

Let's say I had to do the same in T-SQL: I have a customer table, where I had inadvertently inserted last name in the FName column and first name in LName column. How would my T-SQL look like to make this table right?