How to Swap Column Values in SQL Server

In this article, we will show you how to write a query to Swap Column Values in SQL Server with an example. For this Swap Column Values Interview Question, We are going to use the below-shown data.

How to Swap Column Values in SQL Server 1

How to Swap Column Values in SQL Server?

Please use the below-mentioned frequent query to swap two column values.

UPDATE [dbo].[EmployeeDuplicates]
	SET [Education] = [Occupation],
	    [Occupation] = [Education]
GO
Messages
--------
(14 row(s) affected)

Let me show you the updated records. From the screenshot below, you can see that the information in the Education column is stored in the Occupation Column. And data inside the Occupation column is stored in the Education column. Please refer to the SQL CREATE TABLE and Get Column Names from Table articles available on the SQL tutorial page.

How to Swap Column Values using update
Categories SQL