Boolean 'NOT' in T-SQL not working on 'bit' datatype?

前端 未结 7 635
闹比i
闹比i 2020-12-13 23:22

Trying to perform a single boolean NOT operation, it appears that under MS SQL Server 2005, the following block does not work

DECLARE @MyBoolean bit;
SET @My         


        
7条回答
  •  半阙折子戏
    2020-12-13 23:47

    To assign an inverted bit, you'll need to use the bitwise NOT operator. When using the bitwise NOT operator, '~', you have to make sure your column or variable is declared as a bit.

    This won't give you zero:

    Select ~1 
    

    This will:

    select ~convert(bit, 1)
    

    So will this:

    declare @t bit
    set @t=1
    select ~@t
    

提交回复
热议问题