C#
C++
SQL

0 Comments:

Post a Comment



<< Home

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: ,

posted by Brian at