Given the following table:
CREATE TABLE BitValues ( n int )
Is it possible to compute the bitwise-OR of n for all rows with
n
Preparations:
if object_id(N'tempdb..#t', N'U') is not null drop table #t; create table #t ( n int ); insert into #t values (1), (2), (4), (3);
Solution:
select max(n & 8) + max(n & 4) + max(n & 2) + max(n & 1) from #t;