Swap values in a column in sql server


 
I got a query from one of the blog reader. How to swap the values in a column?

There is a column "availability" in a table and it's have 2 values "Yes" or "No".
 
The user have wrongly entered the values. Instead of yes they have inserted No and similary for No, they have entered Yes. How to rectify this problem?
 
Here is the solution to solve this problem

DROP TABLE VENKAT
CREATE TABLE VENKAT(ID INT, NAME VARCHAR(100))
INSERT INTO VENKAT VALUES(1,'VENKAT1')
INSERT INTO VENKAT VALUES(2,'VENKAT2')
INSERT INTO VENKAT VALUES(3,'VENKAT1')
INSERT INTO VENKAT VALUES(4,'VENKAT2')
SELECT * FROM VENKAT
BEGIN TRANSACTION
UPDATE VENKAT SET NAME='VENKAT12' WHERE NAME='VENKAT2'
UPDATE VENKAT SET NAME='VENKAT2' WHERE NAME='VENKAT1'
UPDATE VENKAT SET NAME='VENKAT1' WHERE NAME='VENKAT12'
COMMIT
SELECT * FROM VENKAT

 

 
Cheers,
Venkatesan Prabu .J
http://venkattechnicalblog.blogspot.com/
Ebook Download
View all
Learn
View all