Home > DeveloperSection > Forums > How to Swap the values of two columns in SQL Server.
Ankit Singh

Total Post:341

Points:2389
Posted on    March-03-2016 10:52 PM

 MSSQL Server SQL Server 
Ratings:


 1 Reply(s)
 265  View(s)
Rate this:
We want to Swap the values of two columns in SQL Server. How to do this please Help me.


aditya kumar Patel

Total Post:246

Points:1750
Posted on    March-03-2016 11:00 PM

When you want to swap the values of two columns of a table in SQL Server, how could you achieve this tricky task?.

it is simple like code below.

 

CREATE TABLE [dbo].[Employee] (

[EmpNo] INT IDENTITY (1, 1) NOT NULL,

[EmpName] VARCHAR (50) NOT NULL,

[Salary] DECIMAL (18) NOT NULL,

[DeptName] VARCHAR (50) NOT NULL,

[Designation] VARCHAR (50) NOT NULL,

PRIMARY KEY CLUSTERED ([EmpNo] ASC)

);

select * from [Employee]

 

 

update Employee set Designation=DeptName,DeptName=Designation

 

select * from [Employee]

 

 

 

 


Don't want to miss updates? Please click the below button!

Follow MindStick