Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I need to create a a procedure for calculating a school pass rate. i've got the following queries that i need to use together in 1 proc.

1. count total number of learners in a grade.

SELECT grade, count(learner_id)
FROM learners
GROUP BY grade;

2. count number of learners passed in that grade.

SELECT grade, count(learner_id)
FROM learners
WHERE Status = 'P'
GROUP BY grade;

3. Get the pass rate.

num_passed/tot_num * 100;



Thanks in advance :-)
Posted

Below link may help you to Create new Procedure in SQl Server.
http://msdn.microsoft.com/en-us/library/ms187926.aspx

You can have multiple Queries in your SQL Procedure, And it will return you multiple recordsets based on number of select queries you used in your Procedure.
 
Share this answer
 
Comments
Uday P.Singh 30-Aug-11 10:32am    
nice link my 5!
RaisKazi 30-Aug-11 10:34am    
Thanks Uday
A step by step tutorial[^].
The short of it...
SQL
create procedure [procedure_name]
   -- optionally some params.
   @status char(1)
as
   --your query here
   select someStuff
   from someTable
   where status = @status
end

This SP returns someStuff from someTable where the status is equal to the parameter provided.
Hope that helps! :)

Edit:
I may imply that only simple select statements are possible in an SP. This is not the case however, you can do joins, updates, deletes, use cursors, loops, temp tables, practically do anything in an SP. It doesn't necissarily need a return value either.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900