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

前端 未结 7 647
闹比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:25

    In SQL 2005 there isn't a real boolean value, the bit value is something else really.

    A bit can have three states, 1, 0 and null (because it's data). SQL doesn't automatically convert these to true or false (although, confusingly SQL enterprise manager will)

    The best way to think of bit fields in logic is as an integer that's 1 or 0.

    If you use logic directly on a bit field it will behave like any other value variable - i.e. the logic will be true if it has a value (any value) and false otherwise.

提交回复
热议问题