Randomizing your selection in SQL Server
Sometimes you might want to randomize your dataset. In the SQL driven MP3 player I worked on, I wrote a stored procedure to handle putting together a playlist for the user (since all the song data is already in the database). There are probably a lot of other good uses for random selections and the code sample below works great.
In your select clause you can add an ORDER BY statement and use NEWID().SELECT * FROM
TableName
ORDER BY NEWID()
Labels: SQL, SQL Server
posted by Brian at 5/28/2008 12:33:00 AM
0 Comments:
Post a Comment
<< Home