这个存储过程应该:
将
userid
andDate
作为输入参数检查这是
Id
属于老师还是学生如果用户是学生,它应该输出他一天的主题以及他们每个人将讨论的内容。
如果用户是老师,它应该输出他一天的课程以及他将在每个课程中教什么。
我使用的表格是:
WeeklyPlan (Id, Date, Lesson, Plan)
,Subject (Name, Id)
,Student (userid, name, class)
,Teacher (name, userid)
,TimeTable (subject, day, class)
.
现在我写了这个存储过程(它应该做上面写的),但它没有。
如果我写错了,请您检查一下并给我一些想法?如果我应该以另一种方式提出问题,请告诉我。
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
太感谢了。