Swapping column value in sql
How can I swap column value in sql.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Pradip PandeyPosted Aug 9, 2012, 6:58 AM
Suppose there is a table called
EmpID int
FirstName varchar(50)
LastName varchar(50)
You added some records like this
Insert into Employee(EmpID,FirstName,LastName)Values(1,'Rajput','Manoj')
Insert into Employee(EmpID,FirstName,LastName)Values(2,'Sharma','Gaurav')
Insert into Employee(EmpID,FirstName,LastName)Values(3,'Verma','Deepak')
Actually, you added records wrongly.
Now, by this sql statement, you can swap column value in sql
UPDATE Employee SET LastName=FirstName, FirstName=LastName