How do I crete a ranking for a user in a SQL Server 2000 stored procedure to rank a user based on percentage of questions correct?

I am using ASP.NET vb and SQL SERVER 2000 (not 2005). I need to create a stored procedure (or part of an existing stored procedure that will do the following:

1) Rank a user (from total users that have taken the quiz) on how many answers they have gotten correct.
2) Rank the user based on their percentage of correct answers...i.e. if john doe got 9% of his answers correct. John Doe ranks # 10 of 150 total users.

Please help. I know there are ranking functions Sql server 2005, but I am using 2000. How do I go about doing rankings this way using SQL Server 2000.

Once I have the rankings, I have to output to a page.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dont have the syntax, but if you just calculate the formula for the percent they received, then order by the percent, you will have the order they need to be in.

then use something like this link to create the row number (with the order by will give you the rank)
We would need to see db structure to give you code.

I assume you have a user table.  Then I assume a quiz table, probably a questions table, etc.
Assuming that quiz table are the questions to be asked, and maybe there is a quiz_taken table that represents a user having taken a quiz.  I also assume that you have a field in the quiz_taken table that tells the percent correct. If not you'd have to do another query to get the results.

SELECT u.UserName,qt.PercentCorrect
INNER JOIN Quiz_Taken qt ON u.User_ID=qt.User_ID
INNER JOIN quiz q ON qt.quiz_id=q.quiz_id
ORDER BY qt.PercentCorrect,u.UserName

based on my assumptions, you'd do something like the above.
If you wanted the top percent at the top you'd of course use the DESC keyword in the order statement for qt.PercentCorrect
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

bolenkaAuthor Commented:
actually I only have one table. I have a userAnswers table that is created when the program is opened and then it just updates the answer when the user submits the answer. All of the questions and answers for comparison are in one table...its just what the client had available.

ID(unique) RecordID(testquestionID) UserID UserAnswer, CorrectAnswer, DateSubmitted, Correct, Completed, etc.

I just need to do the rankings based on number of correct answers for that RecordID(for that testquestion)...once I do the calculation for the ranking and other statistics,I insert them to a table called Benchmarks for really, I have the percent corrects already, I just need to rank the user by percents I guess.

If I already have the percents calculated? Do I just order them? I would have to create an ID right to show what the ranking number is?

Does that help?
Obadiah ChristopherCommented:
As you have mentioned you could do the following for generating the id

create a temporary table

declare @table table
    rank int identity(1,1),
    UserID varchar(50),

Now insert into this @table values based on the highest percentage

So basically when u r inserting the one with highest percentage it will give u rank 1 as highest

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
YUCK!  that is terrible design. Oh well.

Try something like this

SELECT Distinct UserID, Count(*) as NumCorrect
WHERE UserAnswer=CorrectAnswer
ORDER BY NumCorrect,UserID

Again you may want the DESC keyword to reverse the order
bolenkaAuthor Commented:
Yes I know...terrible design....but there was not much I could do about it...but thanks for your responses...I will take a look at them and get back to you. Thanks again.
bolenkaAuthor Commented:
informaniac, any chance you could post the syntax?
bolenkaAuthor Commented:
I kind of used a little bit from all suggestions to help me, but I went with the insert to temp table...that was really helpful because I had never written to a temp table before. Thanks so much. I think my rankings are working now. you guys are awesome.
Temp tables are great, but can be misused also.  This is probably a good use for them.  If you have many users who will be viewing this same information again and again, you should consider caching the information for a time to lower the db load.
bolenkaAuthor Commented:
SStory: Thank you for that extra tip. I will keep that in mind.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.