SQL PUZZLE:UPDATING 0 AS 1 AND VICE VERSA IN A BITFIELD
assume a table has a bit column , how will you update all the data that all 1's should be changed as 0 and vice versa
create table #sss(aa int,bb bit)
Insert Into #sss values(1,0)
Insert Into #sss values(2,1)
ANSWER 1.
update #sss set bb = Case bb when 1 then 0 else 1 end --RANJITH P
ANSWER 2.
Update #sss Set bb =Null Where bb=0
Update #sss Set bb =0 Where bb=1
Update #sss Set bb =1 Where bb is null ----- BINEESH THOMAS
--MAJITHA KV
ANSWER 3.
Update #sss set bb =(Select bb from #sss b where aa in (select aa from #sss c where bb <> a.bb))
from #sss a --MAJITHA KV

0 Comments:
Post a Comment
Links to this post:
Create a Link
<< Home