• Jeff Moden (12/22/2008)


    Here's a real cheater method...

    SELECT SIGN(SUM(Col1+0)), SIGN(SUM(Col2+0)), SIGN(SUM(Col3+0))

    FROM SomeTable

    That only works for the first bit. I have a similar problem where we use the first 5 bits as "permissions" on objects and I need to OR the values from multiple rows. Unfortunately, I'm performing RBAR, albeit without a cursor (using SQL Server's multiple row select into a scalar variable approach), in a UDF. E.g.,

    SELECT @v_permissions = ISNULL(@v_permissions, 0) | x.permissions FROM ...

    Any T-SQL tricks? E.g., the following values need to be OR'd together with the result being (decimal) 31.

    [font="Courier New"]Bit Mask Decimal Value

    0000000001 1

    0000000101 5

    0000000111 7

    0000010001 17

    0000010011 19

    0000011101 29[/font]


    [font="Arial Narrow"](PHB) I think we should build an SQL database. (Dilbert) What color do you want that database? (PHB) I think mauve has the most RAM.[/font]