In SQL Server 2022, is there an aggregate function for doing a bit-wise OR against a particular column?
-- Example table, data and output to show the different flags
DECLARE @TEST TABLE (FLAGS TINYINT)
INSERT INTO @TEST VALUES (1), (2), (3), (9), (10)
SELECT FLAGS, FLAGS & 1, FLAGS & 2, FLAGS & 4, FLAGS & 8
FROM @TEST
-- Example output of the above...
FLAGS, FLAG1, FLAG2, FLAG4, FLAG8
1 1 0 0 0
2 0 2 0 0
3 1 2 0 0
9 1 0 0 8
10 0 2 0 8
What I would LIKE to be able to do is find all the flags which have been set
-- Non-existent aggregate to demonstrate what I want
SELECT BIT_OR(FLAGS) FROM @TEST
-- Example output from the above data
FLAGS
11
If there isn't an aggregate (and I can't find one so I guess there isn't)... how can I achieve this?