• christian_nowicki (7/8/2014)


    Using the checksum of a newid as the seed in the rand function does work because the newid is reinterpreted for each row. The only time I'd do it was if I wanted random numbers in a certain range, but I could accomplish this more easily by manipulating the result of the checksum. Try the following query.

    select checksum(newid()) [checksum(newid())],

    rand(checksum(newid())) [rand(checksum(newid()))]

    from information_schema.tables

    Which produces the following

    checksum(newid())rand(checksum(newid()))

    16358037610.986924437232023

    4473023160.681755274955645

    2546138230.41800577680907

    -3939144280.916135911188986

    -14742183580.834318560936923

    -2246331400.59610060597369

    5113407530.131479052219459

    3026621430.144764000770371

    19953135300.67384831581366

    10774383140.646245068324023

    7781166490.981185604553419

    13188310180.796331062731996

    8842640550.907034626273068

    -12349050270.437798511528195

    -7251237140.638412548866134

    11756891450.977022118022555

    21320417380.263610315709295

    -10223100170.127302936488477

    14839420740.587850586235753

    Thank you, Christian, even knowing all these three function (I mean, referring to the BOL) - never used them together like this, this is new and fine example. 🙂

    ww; Raghu
    --
    The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.