Blog

Swap Two Columns Values in SQL Server

By Rohatash Kumar Nov 27 2012
In this blog, You will see how to swap two columns values in SQL Server.
    • Like
    • Love It
    • Awesome
    • Interesting
    • It's Okay
    • Thumbs Down
  • 3.7k
  • 0

In this blog, You will see how to swap two columns values in SQL Server. Here, we create a table and using update command to swap two columns values.

Creating a table in SQL Server

Now we create a table named employee:

Create table Employee

(

EmpID int,

EmpName varchar(30),

EmpSalary int

)

 

The following is the sample data for the employee Table:

 

image1.jpg

Now using Update command to swap Columns Values (Empid, EmpName).

Using Update command

update employee set Empid=EmpSalary, EmpSalary =empid;

select * from employee

Output

image2.jpg