• a_ud (8/3/2015)


    Thanks Jeff, perfect solution. Testing it now.

    I also found this explanation, pretty much in the same line, that also seems easy enough:

    http://blog.sqlauthority.com/2012/11/20/sql-server-using-rand-in-user-defined-functions-udf/

    Thanks for the feedback. The problem with RAND() even in that case is that its a fair bit slower than using NEWID() with the CHECKSUM conversion (which converts it to an INT) as a random source and still requires similar calculations to convert it to a domain constrained set of integers.

    --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)