HOW TO SWAP THE VALUES OF TWO COLUMNS IN SQL SERVER.

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
 575  View(s)
Ratings:
Rate this:
We want to Swap the values of two columns in SQL Server. How to do this please Help me.
  1. aditya kumar Patel

    Post:254

    Points:1810
    Re: How to Swap the values of two columns in SQL Server.

    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]

     

     

     

     

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!