473,394 Members | 1,663 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How can I fix my stored procedure to return the average GPA across all sections?

74 64KB
Hello Everyone,
I have been struggling for hours with trying to figure out how I can return the average GPA across all sections that a professor teaches. Here is the code that I have so far. I know would only need Section and Registration tables in order to output this type of procedure that I want, but it is not producing the right results. Can someone please help me? Here is my ERD model attached below in case you need to know the relationships of each table.

Expand|Select|Wrap|Line Numbers
  1.  USE COLLEGE; 
  2.  
  3.   DROP PROCEDURE IF EXISTS Faculty_GPA ;
  4.  
  5. DELIMITER $$
  6.  
  7. CREATE PROCEDURE Faculty_GPA(IN FacultyID INT,  OUT outavgGPA decimal(4, 2))
  8.  
  9. BEGIN
  10.          DECLARE theGPAInfo DECIMAL(4,2); 
  11.  
  12.          SET theGPAInfo= 
  13.          (SELECT AVG(registration.Grade)
  14.             FROM 
  15.             Registration
  16.             INNER JOIN 
  17.              Student ON registration.ID= Student.ID
  18.              INNER JOIN 
  19.              Section ON Student.ID= Section.ID
  20.              WHERE section.ID= 2 AND section.ID= 3);
  21.  
  22.      SET outavgGPA= theGPAInfo; 
  23. END
  24. $$
  25.  
  26. DELIMITER ;
  27.  
  28.  
  29. CALL Faculty_GPA(2, @averageGPA); 
  30.  
  31.  
  32. SELECT @averageGPA as GPA; 
  33.  
Attached Images
File Type: jpg screenshot1.jpg (48.0 KB, 340 views)
Apr 10 '17 #1
0 2172

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: JT | last post by:
how can i see a stored procedures return value in ASP??
2
by: Mike P | last post by:
I have a SQL Server stored procedure that is returning a 0 if the execution was OK and 1 if not. e.g. : commit trans return 0 on_error: rollback tran
3
by: neil_pat | last post by:
I have a stored procedure which returns a value of between 0 and 4. I want the user to press a button to receive feed back on their last input. The save button takes the input and saves it to...
5
by: Sandy | last post by:
Hello - I need a good example of how to take a return value from a stored procedure and use it in vb code. I have an app that searches a database by city and state. If a user makes a typo, the...
3
by: Adam Knight | last post by:
Hi all, I am wanting to get a stored procedure return value via ADO.NET.. Code: Below:
2
by: Alan T | last post by:
I have a SP: CREATE PROCEDURE dbo.users_name as select name from users order by name Here's my C# code: public string GetUserNames()
2
by: philip | last post by:
hello, i am new to asp.net and sql server, and i have 3 questions for asking: 1. i am writing a store procedure of login validation for my asp.net application and wondering what the different...
1
by: mktilu | last post by:
i want a stored procedure example where it returns both cursor and recordcount as a paramater .
1
by: mazdotnet | last post by:
Hi guys, I can't figure out why this is not working? I need to display all the rows for a given query for a given page index (ex. row 10..20) and the total number of rows. I got the first part...
2
by: brian123 | last post by:
I want to group and then join two tables in a stored procedure and return results to a datareader. The non-grouped data in each table has a many to many relationship. select entity, count(*) as...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.