How
to Swap the values of two columns in SQL Server
Suppose you have a Customer table in the
database with the following data and you want to interchange the values of
columns Name and Address.
SELECT * FROM CUSTOMER
Just write a simple update query for Address
table like as :
UPDATE Customer SET Name=Address , Address=Name
Now After query execution you will find the the
values of columns Name and Address have been interchanged.
Note : If column is identity ,then swapping is
not possible.
SELECT * FROM CUSTOMER
No comments:
Post a Comment