Swapping column value in sql
How can I swap column value in sql.
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Pradip PandeyRank #452 · 5.6K reputationPosted Aug 9, 2012, 2:58 AM EDT
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