How to Swap the values of two columns in SQL Server.

Total Post:341

Points:2389
 915  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. Post:281

    Points:2003
    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