BIT_AND function [Aggregate]

Takes n bit arrays and returns a bitwise AND-ing of its arguments using the following logic: for each bit compared, if all bits are 1, return 1; otherwise, return 0.

Syntax
BIT_AND( bit-expression )
Parameters
  • expression   The expression for which the value is to be determined. This is commonly a column name.

Returns

LONG VARBIT

See also
Standards and compatibility
  • SQL/2003   Vendor extension.

Example

The following example generates four rows containing a CHAR column, then converts the values to VARBIT.

SELECT BIT_AND( CAST(row_value AS VARBIT) ) 
FROM dbo.sa_split_list('0001,0111,0100,0011')

The result 0000 is determined as follows:

  1. A bitwise AND is performed between row 1 (0001) and row 2 (0111), resulting in 0001 (both values had a 1 in the fourth bit).

  2. A bitwise AND is performed between the result from the previous comparison (0001) and row 3 (0100), resulting in 0000 (neither value had a 1 in the same bit).

  3. A bitwise AND is performed between the result from the previous comparison (0000) and row 4 (0011), resulting in 0000 (neither value had a 1 in the same bit).