SQL NET - A Place to talk on MS SQL Server and other database tools

Talks on SQL Server, database development, data management techniques,SQLBI/SSIS/SSAS/SSRS etc. Want to publish something db related ? mail to bineeshthomas@gmail.com with subject line starting as "SQLNET"

SQL NET FORUM

Portal Maintained By : BINEESH THOMAS

Friday, August 14, 2009

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

Free Domain Name - www.YOU.co.nr!