Hassan Alrawashdeh Hassan Alrawashdeh - 4 months ago 8
SQL Question

sql value or column values

I work on SQL server 2012, i have a value x and a column y contain some values (y1, y2, ..., yn)

i want to do bitwise or between x and y column

i perform

SELECT x | y
FROM someTable


which returns
x | y1


can someone tell me how to do it please

Answer
create function getBitwiseOr(@data int, @k int)
returns int
as
begin
declare @consolidated int;
set @consolidated = @k
return @consolidated|@data
end
go


declare @x int, @k int;
SET @x=inputValue;
SET @k = 0;

select @k = dbo.getBitwiseOr((@x|Yvalue),@k) from HassanData
PRINT @k //this is the consolidated value