Aggregate bitwise-OR in a subquery

后端 未结 10 2027
醉酒成梦
醉酒成梦 2020-11-30 08:46

Given the following table:

CREATE TABLE BitValues ( n int )

Is it possible to compute the bitwise-OR of n for all rows with

10条回答
  •  南笙
    南笙 (楼主)
    2020-11-30 09:01

    I tried using COALESCE function and it works, example:

    DECLARE @nOrTotal INT
    
    SELECT @nOrTotal = COALESCE(@nOrTotal, 0) | nValor 
        FROM (SELECT 1 nValor
                  UNION 
              SELECT 2
                  UNION 
              SELECT 2) t
    
    SELECT @nOrTotal
    
    >> Result: 3
    

提交回复
热议问题