CheckSum routine

  • Is there any way I can calculate a checksum digit using 'Sum of Product - Mod 10' method without looping through each digit?

    What I mean by 'Sum of Product - Mod 10' is:

    - Multiply each digit with 1 or 2 and sum the result of all such calculations on each digit

    - Check sum digit is = 10 - (Sum % 10)

     

    Example string : 02530010828400000008607

     

    Thanks.

  • Not sure if it uses the 'Sum of Product - Mod 10' method you were talking about but...

    Have you tried the CHECKSUM function in SQL?  It's in "Books on line".

    --Jeff Moden

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

  • CHECKSUM routine is used to get a unique (in almost all cases but no guarantees) numeric value for a column value so that this unique value can be used to create performance enhancing indices.  I can't find the underlying implementation of the routine but it does not return a check digit

    I have created a stored proc that returns my check digit value on any string using the Mod-10 Sum of Product method.  It serves my purpose.  I was looking for something similar to CHECKSUM that I can apply to the string directly rather than looping through each digit in the string.  Anyway, thanks.

  • Farhan,

    Would you be willing to shared code of your stored procedure... We have a need for same.

  • If you want to get a checksum against the full table you can do something like the following...

    SELECT CHECKSUM_AGG(BINARY_CHECKSUM(*))

    FROM Foo WITH(NOLOCK)




    Gary Johnson
    Microsoft Natural Language Group
    DBA, Sr. DB Engineer

    This posting is provided "AS IS" with no warranties, and confers no rights. The opinions expressed in this post are my own and may not reflect that of my employer.

  • Hrm.  the _agg version is not something I was familiar with.  Thanks

    /hijack off

  • Can anyone give me the code for a stored procedure in order to check the validity of a code using the Check Digit Algorithm (Modulus 10).

  • I have a function that does it all for you. Inparameters are data and boolean wether or not checkdigit is included.

    Return value is either checkdigit or true/false if checkdigit was included

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

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