Thursday, September 30, 2010

SQL "not" for a variable

in c# i have a:

a = !a
(if false makes it true, if true makes it false)

in sql i want to do the same with a BIT variable, something like:


declare @a bit
set @a = 1
select @a
set @a = not (@a)
select @a


can i?

i could always do an IF, but this would "look better" :)

with the help of stackoverflow.com:
you can do either:
1. @a = @a ^ 1
or
2. @a = ~@a

i personally prefer #2

No comments: