SQL Server Performance

Random Numbers

Discussion in 'General Developer Questions' started by Raulie, Jul 30, 2004.

  1. Raulie New Member

    Does anyone happen to have any code to update a table column with random integers?
    Also if you got something similiar with dates but in order that would be nice too.

    Regards
  2. Luis Martin Moderator

    Would the following help?

    SELECT RAND( (DATEPART(mm, GETDATE()) * 100000 )
    + (DATEPART(ss, GETDATE()) * 1000 )
    + DATEPART(ms, GETDATE()) )

    You can convert to integer after Rand.

    HTH


    Luis Martin
    Moderator
    SQL-Server-Performance.com

    All postings are provided “AS IS” with no warranties for accuracy.

  3. FrankKalis Moderator

    I would have also suggested something using RAND(). However, RAND is a poor randomizer, so if that's for something statistical you're better off doing this at the client. Or build a number table of a given range and do a SELECT TOP 1 blahblah ORDER BY NEWID().

    HTH



    --Frank
    http://www.insidesql.de
  4. satya Moderator

  5. Raulie New Member

    Thanks alot Luis, Frank and Satya. [<img src='/community/emoticons/emotion-2.gif' alt=':D' />] I've tried numerous functions but performance is very poor with large tables. Frank I'm gonna try your original suggestion. Thanks!

Share This Page