-1

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

2
  • 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
0
select case when a1 + a2 + a3 > 0 then 1
       else 0 end as F from table1

  
1

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

https://docs.microsoft.com/en-us/sql/t-sql/language-elements/bitwise-operators-transact-sql?view=sql-server-ver15

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.