Friday, June 29, 2007

T-SQL bitwise not

Today I stumbled upon a feature in T-Sql that I haven't found before. I was looking for a way to do a bitwise not. I've seen this done with a case statement in a couple of places however it's clumsy and verbose:

CASE WHEN my_bit_f = 1 THEN 0 ELSE 1 END

Instead this can be simplified to:

~my_bit_f


MSDN:
http://msdn2.microsoft.com/en-us/library/ms173468.aspx