locked
Looking for a randomize function RRS feed

  • Question

  • Hi everyone,

    Primary platform is Sql2k

    I'd like to have available a function which retrieves a random row.

    Does anyone have ever used or faced this requirement?

    Thanks in advance for any input or advice

     

    Friday, February 23, 2007 10:02 AM

Answers

  • Try ordering your resultset by NEWID() to see if this meets your requirements.

    i.e.

    SELECT TOP 1 *

    FROM MyTable

    ORDER BY NEWID()

     

    Chris

     

    Friday, February 23, 2007 10:07 AM

All replies

  • Try ordering your resultset by NEWID() to see if this meets your requirements.

    i.e.

    SELECT TOP 1 *

    FROM MyTable

    ORDER BY NEWID()

     

    Chris

     

    Friday, February 23, 2007 10:07 AM
  • It was useful for us. Thanks for that.
    Friday, February 23, 2007 11:13 AM