How do I swap column values in sql server 2008?
I have a table called Employee
Eno ename AttributeValue AttributeName
1 aa a123 abc
2 bbb b123 dcf
3 cc c7sd wew3
I want to swap the data from column AttributeValue
to AttributeName
and AttributeName
to AttributeValue
For Example:
Eno ename AttributeValue AttributeName
1 aa abc a123
2 bbb dcf b123
3 cc wew3 c7sd
Solution 1:
UPDATE employee
SET AttributeValue = AttributeName,
AttributeName = AttributeValue
However, unless both columns have the exact same definition, you risk losing information.
Solution 2:
Update employee
Set attributeValue = attributeName,
attributeName = attributeValue
Solution 3:
update Employee set AttributeValue = AttributeName, AttributeName = AttributeValue