I have few columns which has values either 1 or 0. Final result i have to store in one column(F), Which should perform OR operation.

enter image description here

  • Final result of what operation? – Learning_DBAdmin Apr 6 at 7:43
  • @Learning_DBAdmin Coulmn F should have 1 when there is 1 in any one of the columns(a1,a2,a3)--OR operation – Teju Apr 6 at 7:47
select case when a1 + a2 + a3 > 0 then 1
       else 0 end as F from table1


These are known as bitwise operators & described in the MS documentation. By the sound of it the one you want is a pipe |

create table #t (cola bit,colb bit, colc bit) 

insert #t values(1,0,1)
insert #t values(1,1,0)
insert #t values(0,0,0)

select cola|colb|colc from #t


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.