Return to Snippet

Revision: 3741
at September 9, 2007 19:17 by rengber


Initial Code
BEGIN 
DECLARE @MailDelivery int, 
        @EmailDelivery int, 
        @FaxDelivery int, 
        @ParamVal int, 
        @ZeroVal int

set @MailDelivery  = 1 --(0001)
set @EmailDelivery = 2 --(0010)
set @FaxDelivery   = 4 --(0100)

set @ParamVal = 1
set @ZeroVal =  0

if @ParamVal = 0
set @ZeroVal = null

set @ParamVal = isnull(@ParamVal, 0)

SELECT Id, 
       --BusinessEventDate, 
       DeliveryFlags, 
       (isnull(DeliveryFlags,0) & @ParamVal) as BitMask 
FROM   Mailsets
WHERE (BusinessEventDate > '8/28/2007')
--Check the appropriate bit.  
  AND (
        (isnull(DeliveryFlags,0) & @ParamVal) = @ParamVal + isnull(@ZeroVal, isnull(DeliveryFlags,0))
      )

END 
GO

Initial URL

                                

Initial Description

                                

Initial Title
Using a BitMask in a Where Clause

Initial Tags
sql

Initial Language
SQL