日期:2014-05-17 浏览次数:20441 次
--如果数据中除了1和0以外有其他数字的话会有影响 DECLARE @T TABLE(ID INT,[COL] INT) INSERT @T SELECT 1,1 UNION ALL SELECT 2,1 UNION ALL SELECT 3,0 UNION ALL SELECT 4,0 UNION ALL SELECT 5,2 UPDATE @T SET COL=COL^1 FROM @T SELECT * FROM @T /* ID COL ----------- ----------- 1 0 2 0 3 1 4 1 5 3 */ --如果数据中除了1和0以外有其他数字的话会有影响 DECLARE @T1 TABLE(ID INT,[COL] INT) INSERT @T1 SELECT 1,1 UNION ALL SELECT 2,1 UNION ALL SELECT 3,0 UNION ALL SELECT 4,0 UNION ALL SELECT 5,2 UPDATE @T1 SET COL=1-COL FROM @T1 --WHERE ID=1 SELECT * FROM @T1 /* ID COL ----------- ----------- 1 0 2 0 3 1 4 1 5 -1 */ --如果数据中除了1和0以外有其他数字的话没有影响 DECLARE @T2 TABLE(ID INT,[COL] INT) INSERT @T2 SELECT 1,1 UNION ALL SELECT 2,1 UNION ALL SELECT 3,0 UNION ALL SELECT 4,0 UNION ALL SELECT 5,2 UPDATE @T2 SET COL=CASE COL WHEN 1 THEN 0 WHEN 0 THEN 1 ELSE COL END FROM @T2 --WHERE ID=1 SELECT * FROM @T2 /* ID COL ----------- ----------- 1 0 2 0 3 1 4 1 5 2 */