Basic Question - not vs. =

  • Suppose you have

    declare @bBit bit

    To check the TRUE/FALSE of @bBit, which is better:

    if not @bBit

    or

    if ( @bBit = 0 )

     

    Your inputs appreciated.

     

    --

  • The BIT datatype is described as an "Integer data type" - see BOL.  I do not believe the syntax "not @bbit" will be accepted in the SQL code.

    Guarddata-

  • Oops!

    What I am trying to get at is,

    is not (value)

    better, or

    is ( value = false )

    better.

    I just used the T-SQL syntax on the fly, so completely missed the bit is integer bit!

    --

  • When I try to execute SQL code of not (value) or not @variable, I get syntax errors.  All our routines check for @bbit = 0 for false  and @bbit = 1 for true.  The real advantage (to us, at least) in using a BIT datatype is that anything non-zero gets converted to a 1 so you are sure of the evaluations.  We still tend to use TINYINT to permit future flexibility of using more values.

    Guarddata-

  • '=' will almost always be faster than NOT or != (not equal) Check your optimization plan to confirm and also use "set statistics IO on" to see logical IO.

    HTH

     

    ------------

    Ray Higdon MCSE, MCDBA, CCNA

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply