CHECKSUM() and NULL

  • Thomas Franz

    Hall of Fame

    Points: 3534

    Comments posted to this topic are about the item CHECKSUM() and NULL

    God is real, unless declared integer.

  • HappyGeek

    SSCoach

    Points: 18661

    Good question many thanks.

    ...

  • Stewart "Arturius" Campbell

    SSC Guru

    Points: 71314

    Nice one, thanks Thomas

    ____________________________________________
    Space, the final frontier? not any more...
    All limits henceforth are self-imposed.
    “libera tute vulgaris ex”

  • Ed Wagner

    SSC Guru

    Points: 286957

    Very nice question about a function I use with some frequency.  Thanks.

  • Budd

    Hall of Fame

    Points: 3575

    Well done !!

  • x

    SSC-Insane

    Points: 23352

    Given the behavior of nulls elsewhere, I surely expected this function to also return null. I'm guessing that maybe that would invalidate the practicality of the checksum function, so an interesting design choice on that one!

  • TomThomson

    SSC Guru

    Points: 104763

    Nice question.  

    It's rather a pity that checksum doesn't take account of the type of a NULL, but that will only very rarely be a pain. 

    The documentation is awful, though:  "CHECKSUM applied over any two lists of expressions returns the same value if the corresponding elements of the two lists have the same type and are equal when compared using the equals (=) operator. For this definition, null values of a specified type are considered to compare as equal" is likely to mislead people into believeing that NULLs of different type don't make the same contribution to a checksum, and that values that compare as equal don't have the same checksum if they have different types.  This mostly isn't a problem, because comparing checksums of things whose types don't match is a bit crazy anyway.   But that text on teh BOL page really looks silly when a string containing 3 characters existsing as things with types char(26), varchar(107), and varchar(max)  will have the same checksum  or each of those types, regardless of whether ANSI_PADDING is ON or OFF.   That really does make the documentation look as is it is designed to mislead.

    Tom

Viewing 7 posts - 1 through 7 (of 7 total)

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