Swap Two Columns Values in SQL Server

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

Ebook Download
View all
Learn
View all