Home > DeveloperSection > Forums > random questions from sql server
lois waisbrooker
lois waisbrooker

Total Post:70

Posted on    May-07-2013 12:23 AM

 MSSQL Server MSSQL Server 

 1 Reply(s)
 832  View(s)
Rate this:
Hi! Everyone!

I am working on a survey application. I have a sql server database holding upto 3000 survey questions. I call database for a set of 10 questions. I have to make sure 

that none of the of the questions are repeated for the longest time possible. What is the best possible approach I can take here? Write a custom randomization 

algorithm or SQL server provides some functionality.

Please help me!

Thanks in advance!


Total Post:604

Posted on    May-07-2013 7:44 AM

Hi Loos!

SELECT question_id
FROM questions 
gives you all the question ids in random order. store the list, and work your way down.

There isn't a way to ensure the longest time between repeats without storing the order. You could make it another column on the same table...

EDIT: a variation on Mr Jacques' idea:

how about a column named random? Shuffle the order like so:

update questions set random = (
    SELECT question_id
    FROM questions 
then get each new question like this:

select * where random = 'prev_question_id';
Then you could shuffle the order at intervals, every night maybe.

Don't want to miss updates? Please click the below button!

Follow MindStick