Trying something I thought always worked for me but getting weird results now.
One of the columns in my table is called RefBD (Brain Dead Referrals) and is either 1 or 0.
Select SUM(RefBD) ...
gives me the total number of records with a 1, aka the total brain dead referrals. If I have 2000 records and 1500 brain dead referrals then this would return 1500
Select SUM(~RefBD) ...
gives me negative numbers for the result when I expect it to return 500. I cannot figure why?
According to SQL 2005 BOL:
The ~ bitwise operator performs a bitwise logical NOT for the expression, taking each bit in turn. If expression has a value of 0, the bits in the result set are set to 1; otherwise, the bit in the result is cleared to a value of 0. In other words, ones are changed to zeros and zeros are changed to ones.
I know that I could use
SUM(1 - RefBD) or SUM(RefBD ^ 1)