How to randomly pick exam questions from database(sql server)

  • 10 years ago

    i'm implementing an examination system. Did anyone know how to randomly pick exam questions from the database. i'm using sql server 2000 and

  • 10 years ago

    You can select a random row using following stored procedure:

    Declare @LastId int, @RndId int, @Lower int, @Upper int

    Select @LastId = Max(QuestionId) From dbo.Questions

    SET @Lower = 1
    SET @Upper = @LastId
    SELECT @RndId = Round(((@Upper - @Lower -1) * Rand() + @Lower), 0)

    If Exists(Select * From dbo.Questions Where (QuestionId = @RndId))
    Select * From dbo.Questions Where (QuestionId = @RndId)
    Goto Gen_Rnd
  • 10 years ago

    ok. but using this code i hv to pass question id then only able to retrieve..but for my system when i click the start exam button , the first question should randomly pick from the database and appear(the user no need to gv the question id).....and another thing is there any possibilities to code it in meee

  • 10 years ago

    I'm not sure if this will assist you in your situation but I have used

    SELECT TOP 10 * FROM tblExamQuestions ORDER BY newID()

    This SELECTs 10 rows randomly from the table...



  • 10 years ago

    ya it;s help me alot thank you....

Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“A computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match” - Bill Bryson