• a_ud (8/21/2012)


    Thanks Sean. By now I've got a very clear idea of what the (mod 23) code does in SQL (code in VBA still pending).

    Basically it takes a number 'ID' like '1234' and calculates the following in each iteration 'i':

    i | mod | mod + i*substring(id,i1)

    1 | 0 0+1 *1=1

    2 | 1 | 1+2*2 = 5

    .........

    7 | .... | 30

    Then 30 mod 23 = 7 --> and 7+1 would be the value used for looking up the corresponding letter, an H ("ABCDEFGHJKLMNPQRSTVWXYZ"). This can be translated into VBA relatively easily, since Substring is equivalent to Excel function Mid.

    Hope this helps someone, a.

    I can understand the sql part but what I can't understand is what the business rule for this is. It is a very strange algorithm to pick a letter. I am curious what this is used for and the logic is the way it is.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/