How do I flip a bit in SQL Server?

Even Mien picture Even Mien · Oct 5, 2008 · Viewed 24.9k times · Source

I'm trying to perform a bitwise NOT in SQL Server. I'd like to do something like this:

update foo
set Sync = NOT @IsNew

Note: I started writing this and found out the answer to my own question before I finished. I still wanted to share with the community, since this piece of documentation was lacking on MSDN (until I added it to the Community Content there, too).

Answer

Jason Kresowaty picture Jason Kresowaty · Oct 5, 2008

Yes, the ~ operator will work.

update foo
set Sync = ~@IsNew