billpg
billpg

Reputation: 3293

SQL Server - Shuffle results randomly, but with a weight assigned to each record

I know that the normal way to shuffle results with SQL Server is to order by NEWID(), except I'd like to instead use a weighted shuffle.

Each record in my table has an integer 'Importance' from 1 to 10. I'd like to order by RAND()*Importance, except SQL Server has RAND() return the same value for each record returned.

Any ideas please?

Upvotes: 1

Views: 1085

Answers (1)

SQLMenace
SQLMenace

Reputation: 135021

Take a look at SQL Server - Set based random numbers for some ideas

Upvotes: 1

Related Questions