Converting 0 to 1 and 1 to 0 in a SQL Server Table


Please check the below code,

 

DROP TABLE VENKAT_SAMPLETABLE
CREATE TABLE VENKAT_SAMPLETABLE(ID INT)
INSERT INTO VENKAT_SAMPLETABLE VALUES(1)
INSERT INTO VENKAT_SAMPLETABLE VALUES(0)
INSERT INTO VENKAT_SAMPLETABLE VALUES(0)
INSERT INTO VENKAT_SAMPLETABLE VALUES(1)
SELECT * FROM VENKAT_SAMPLETABLE
UPDATE VENKAT_SAMPLETABLE
   SET ID=
   (   CASE
      WHEN ID=1  THEN 0
      WHEN ID=0  THEN 1
     END)
SELECT * FROM VENKAT_SAMPLETABLE
 


1.jpg

Cheers,
Venkatesan Prabu .J
Head - www.kaashivinfotech.com
http://venkattechnicalblog.blogspot.com/