Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7751567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:34:55+00:00 2026-06-01T11:34:55+00:00

This stored procedure is supposed to : Take the userid and Date as input

  • 0

This stored procedure is supposed to :

  1. Take the userid and Date as input parameters

  2. Check whether this Id belongs to a teacher or a student

  3. If the user is a student, it should output his day’s subjects and what each of them will discuss.

  4. If the user is a teacher, it should output his day’s classes and what he’ll teach at each of them.

  5. The tables which I use are: WeeklyPlan (Id, Date, Lesson, Plan), Subject (Name, Id), Student (userid, name, class), Teacher (name, userid), TimeTable (subject, day, class).

Now I Wrote this stored procedure (which it is supposed to do what’s written above), but It doesn’t.

So would you please check it & give me ideas if I wrote it wrong? And if I should ask a question in another way, please tell me.

   ALTER PROCEDURE dbo.GetDaySubjects
   (
       @UserId int,
       @DateToday DateTime 
   )
   AS
   IF EXISTS(SELECT        Std_UserID
      FROM            Student
      WHERE        (Std_UserID = @UserId))

              BEGIN 
     SELECT        WeeklyPlan.Wkp_Body, WeeklyPlan.Wkp_Date, WeeklyPlan.Wkp_lesson
     FROM            Class INNER JOIN
                     Student ON Class.Cls_ID = Student.Std_Class INNER JOIN
                     TimeTable ON Class.Cls_ID = TimeTable.Ttb_Class INNER JOIN
                     Subject ON TimeTable.Ttb_Subject = Subject.sbj_ID INNER JOIN
                     WeeklyPlan ON Subject.sbj_Name = WeeklyPlan.Wkp_lesson
     WHERE        (WeeklyPlan.Wkp_Date = @DateToday)
       END

     ELSE IF EXISTS(SELECT        Tch_UserID
           FROM            Teacher
           WHERE        (Tch_UserID = @UserId))

           BEGIN

       SELECT        TimeTable.Ttb_Class, WeeklyPlan.Wkp_lesson, WeeklyPlan.Wkp_Body,              Teacher.Tch_ID

       FROM            Subject INNER JOIN
                     TimeTable ON Subject.sbj_ID = TimeTable.Ttb_Subject INNER JOIN
                     WeeklyPlan ON Subject.sbj_Name = WeeklyPlan.Wkp_lesson INNER JOIN
                     Teacher ON TimeTable.Ttb_Teacher = Teacher.Tch_ID
        WHERE        (WeeklyPlan.Wkp_Date = @DateToday)
           END

Thank you so much.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T11:34:56+00:00Added an answer on June 1, 2026 at 11:34 am

    What I can understand of your database structure and what you want. Is that you are missing in you where statement to sepcify which user that has this schedule.

    WHERE        (WeeklyPlan.Wkp_Date = @DateToday) 
                 AND Student.Std_UserID=@UserId
    

    And the second one:

    WHERE        (WeeklyPlan.Wkp_Date = @DateToday)
                 AND Teacher.Tch_UserID = @UserId
    

    But I agree on the comment of your question. So I think you might consider splitting this PROC in two. One that fetches the Student and one that fetches the Teacher. Then both of the EXISTS(..) is obsolete.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an MSSQL2005 stored procedure here, which is supposed to take an XML
I have this stored procedure: CREATE OR REPLACE PROCEDURE LIQUIDACION_OBTENER ( p_Cuenta IN NUMBER,
I have this stored procedure for Oracle: create or replace procedure bns_saa_message_get() <--- PROBLEM
Can anyone please point out what im doing wrong with this Stored Procedure please.
Well I have this MySQL stored procedure that I wrote and if I run
This code involves a recursive Stored Procedure call and a not so great method
I have a mysql stored procedure from this ( google book ), and one
I've got a mySql stored procedure that looks like this-- delimiter | create procedure
I have a stored procedure and if the stored procedure does this: SELECT 0
If I have this stored proc definition minus the body ALTER PROCEDURE sp_AlloctionReport(@where NVARCHAR(1000),

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.