• dwain.c (3/26/2012)


    Jeff,

    The following thought occurred to me last night but I didn't get a chance to test it until this morning.

    Isn't the modulo function designed to always return a positive integer?

    Hence, in this part of your data generator, I don't believe you need to use ABS:

    SomeRandomInteger = CHECKSUM(NEWID()) % @Range + @StartValue

    I didn't try it for a million rows but the first 200 came up all as positives.

    Apologies, Dwain. I'm not sure how I missed your question on this.

    As Michael demonstrated, Modulo will return a negative number if the "Dividend" of the division is negative.

    SELECT -1111 % 100,

    1111 %-100,

    -1111 %-100

    ----------- ----------- -----------

    -11 11 -11

    (1 row(s) affected)

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