Swap Two Columns Values in SQL Server

Introduction

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

Creating a table in SQL Server

Now, swap Columns Values (Empid, EmpName) using the Update command. 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

 

Using Update command

update employee set Empid=EmpSalary, EmpSalary =empid;
select * from employee

Output

image2.jpg