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.

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

Rohatash Kumar

Normal 0 false false false EN-AU X-NONE X-NONE I am a Microsoft .NET software Developer and author and C# Corner MVP. I hold Masters degree i... Read more

COMMENT USING

PREMIUM SPONSORS

Hire Mobile & Web Developer on demand. 100% satisfaction. Try for 1 week or Money Back. Local and remote developers available all over USA.

Latest Blogs