Tuesday, December 11, 2007

Querying for random results

--You can catch up rows at random by means of NEWID() function (either Sql2k or Sql25k)

SELECT TOP 1 *
FROM
ORDER BY NEWID()

--And this one is useful when you want to obtain a LONG random value (either Sql2k or Sql25k)

SELECT right(cast(rand(checksum(newid())) as decimal(15, 15)), 15)

0 Comments:

Post a Comment

<< Home