• Here's another example of using the AND (&) operator to query an integer being used as a bit-map. You may have a set of integers, each representing the calendar for a month. You can set bits in each to indicate certain days, perhaps weekends and holidays. For this month, July 2013, here in the U.S. we would set the bits for the four weekends and for the holiday on the fourth of July. Then, we can use the & operator to query whether a particular date in the month is not a business day:

    declare @monthCalendar int

    set @monthCalendar = power(2,4) -- set bits for the holiday and the four weekends

    + power(2,6)

    + power(2,7)

    + power(2,13)

    + power(2,14)

    + power(2,20)

    + power(2,21)

    + power(2,27)

    + power(2,28)

    declare @dateInMonth int

    set @dateInMonth = 4 -- check this date in the month

    declare @dateBitValue int

    set @dateBitValue = power(2,@dateInMonth)

    Select @monthCalendar as MonthCalendar -- this integer may have been stored in your db somewhere

    ,Case when @monthCalendar & @dateBitValue > 0 then 'Yes' Else 'No' end as DateIsSelected