random questions from sql server

Total Post:70


 1693  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!
  1. Re: random questions from sql server

    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 
        ORDER BY NEWID()
    then get each new question like this:

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


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.