• DataDog (1/13/2010)


    I haven't seen mention of this important NULL topic anywhere:

    select 1

    where 1 = 1 or datediff(hour, null, getdate()) > 4

    TSQL seems to work like this:

    where True OR NULL = True

    where False OR NULL = False

    where True AND NULL = False

    where False AND NULL = False

    which seems good to me

    but I still think this syntax would be useful:

    where coalesce(datediff(hour, [field], getdate()) > 4, 0)

    letting you coalesce a boolean without using dummy values

    Actually, this:

    datediff(hour, null, getdate()) > 4

    Works out to this:

    NULL > 4

    Which returns 'UNKNOWN'. So your truth table entry for:

    where 1 = 1 or datediff(hour, null, getdate()) > 4

    Is actually:

    True OR Unknown = True

    That's covered fairly well in a lot of places--a lot of articles on this site, for instance or BOL.

    Thanks

    Mike C