Blog

Swap Two Columns Values in SQL Server

Posted by Rohatash Kumar Blogs | SQL 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

post comment
     
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Join a Chapter