Saturday, September 03, 2005
« Back into the Rhythm | Main | Skonnard on Indigo »

A buddy of mine pointed me to this blog post today.  He had the need to pull a single random record from a database table.  Traditionally, this has not been a completely trivial task, but not unattainable either.  Well, the technique employed here is pretty cool.  All you need to do is leverage the NewID() function in SQL Server 2000+.

SELECT TOP 1 * FROM tblSomeTable ORDER BY NEWID()

Pretty slick, eh?

Saturday, September 03, 2005 1:58:00 PM (Mountain Standard Time, UTC-07:00)  #    Disclaimer  |  Comments [0]  |  Trackback