You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Zliczenie frekwencji danego uczestnika na danym kursie
CREATEFUNCTIONGetCourseAttendanceForStudent(@StudentID int, @CourseID int)
RETURNS REALASBEGIN
IF NOT EXISTS (SELECT*FROM Students WHERE StudentID = @StudentID)
BEGIN--jeżeli nie znaleziono studenta
RETURN 0.0;
END
IF NOT EXISTS (SELECT*FROM Courses WHERE CourseID = @CourseID)
BEGIN--jeżeli nie znaleziono kursu
RETURN 0.0;
END
IF NOT EXISTS (SELECT*FROM CourseModulesDetails AS cmd
JOIN CourseModules AS cm ONcmd.ModuleID=cm.ModuleIDWHERE StudentID = @StudentID AND CourseID = @CourseID)
BEGIN--jeżeli student nie był zapisany na ten kurs
RETURN 0.0;
END
DECLARE @AttendanceCount INT;
DECLARE @ModulesCount INT;
SELECT @AttendanceCount =COUNT(*)
FROM CourseModulesDetails AS cmd JOIN CourseModules AS cm
ONcmd.ModuleID=cm.ModuleIDWHERE StudentID = @StudentID AND Presence =1AND CourseID = @CourseID ANDDate< GETDATE();
SELECT @AttendanceCount =COUNT(*)
FROM CourseModulesDetails AS cmd JOIN CourseModules AS cm
ONcmd.ModuleID=cm.ModuleIDWHERE StudentID = @StudentID AND CourseID = @CourseID ANDDate< GETDATE();
RETURN @AttendanceCount / @ModulesCount;
END;
Zliczenie frekwencji danego uczestnika na danym przedmiocie na studiach
CREATEFUNCTIONGetSubjectAttendanceForStudent(@StudentID int, @SubjectID int)
RETURNS REALASBEGIN
IF NOT EXISTS (SELECT*FROM Students WHERE StudentID = @StudentID)
BEGIN--jeżeli nie znaleziono studenta
RETURN 0.0;
END
IF NOT EXISTS (SELECT*FROM Subject WHERE SubjectID = @SubjectID)
BEGIN--jeżeli nie znaleziono przedmiotu
RETURN 0.0;
END
IF NOT EXISTS (SELECT*FROM StudyMeetingDetails AS smd
JOIN StudyMeeting AS sm ONsmd.StudyMeetingID=sm.StudyMeetingIDWHERE StudentID = @StudentID AND SubjectID = @SubjectID)
BEGIN--jeżeli student nie był zapisany na zajęcia z tego przedmiotu
RETURN 0.0;
END
DECLARE @AttendanceCount INT;
DECLARE @MeetingsCount INT;
SELECT @AttendanceCount =COUNT(*)
FROM StudyMeetingDetails AS smd JOIN StudyMeeting AS sm
ONsmd.StudyMeetingID=sm.StudyMeetingIDWHERE StudentID = @StudentID AND Presence =1AND SubjectID = @SubjectID ANDDate< GETDATE();
SELECT @MeetingsCount =COUNT(*)
FROM StudyMeetingDetails AS smd JOIN StudyMeeting AS sm
ONsmd.StudyMeetingID=sm.StudyMeetingIDWHERE StudentID = @StudentID AND SubjectID = @SubjectID ANDDate< GETDATE();
RETURN @AttendanceCount / @MeetingsCount;
END;
Wyliczenie maksymalnej ilości miejsc na kursie
CREATEFUNCTIONGetMaxCourseCapacity(@CourseID int)
RETURNS intASBEGIN
DECLARE @MaxCapacity int;
SELECT @MaxCapacity =MIN(StationaryModule.Limit)
FROM StationaryModule
INNER JOIN CourseModules ONStationaryModule.ModuleID=CourseModules.ModuleIDWHERECourseModules.CourseID= @CourseID;
RETURN @MaxCapacity -- if there are no stationary meetings there is no limit so function returns NULL
END
Wyliczenie maksymalnej ilości miejsc na studiach
CREATEFUNCTIONGetMaxStudyCapacity(@StudiesID int)
RETURNS intASBEGIN
DECLARE @MaxCapacity int;
SELECT @MaxCapacity =MIN(StationaryMeeting.Limit)
FROM StationaryMeeting
INNER JOIN StudyMeeting ONStationaryMeeting.MeetingID=StudyMeeting.StudyMeetingIDINNER JOIN Subject ONStudyMeeting.SubjectID=Subject.SubjectIDWHERESubject.StudiesID= @StudiesID;
RETURN @MaxCapacity -- if there are no stationary meetings there is no limit so function returns NULL
END
Sprawdzenie czy student odbył praktyki raz na pół roku i czy miał na nich 100% frekwencji
CREATEFUNCTIONCheckStudentInternships(@StudentID int)
RETURNS bitASBEGIN
DECLARE @Result bit=0-- Sprawdzamy, czy student o danym ID należy do jakichkolwiek studiów
IF EXISTS (SELECT1FROM StudiesDetails WHERE StudentID = @StudentID)
BEGIN-- Sprawdzamy, które praktyki są przypisane do danych studiów i czy już się zakończyły
IF NOT EXISTS (
SELECT1FROM Internship i
INNER JOIN StudiesDetails ss ONi.StudiesID=ss.StudiesIDWHEREss.StudentID= @StudentID
ANDi.StartDate<= GETDATE() -14-- Praktyki trwają zawsze 14 dni
)
BEGIN-- Sprawdzamy, czy student zaliczył wszystkie praktyki
IF NOT EXISTS (
SELECT1FROM InternshipDetails id
INNER JOIN Internship i ONid.InternshipID=i.InternshipIDWHEREi.StartDate<= GETDATE() -14ANDid.StudentID= @StudentID
ANDid.DidAttend=0-- Jeżeli istnieje praktyka, której student nie zaliczył
)
BEGINSET @Result =1-- Zwracamy true, jeżeli student odbył wszystkie praktyki
END
END
END
RETURN @Result
END
Sprawdzenie, czy podana kombinacja tłumacza i języka jest dozwolona (albo obu nie podano, albo jeżeli podano. to tłumacz zna język)
CREATEFUNCTIONCheckTranslatorLanguage
(@TranslatorID intnull, @LanguageID intnull)
RETURNS bitASBEGIN
IF @TranslatorID IS NOT NULLAND NOT EXISTS (SELECT*FROM Translators WHERE TranslatorID = @TranslatorID)
BEGIN
RETURN CAST(0ASbit)
END
IF @LanguageID IS NOT NULLAND NOT EXISTS (SELECT*FROM PossibleLanguages WHERE LanguageID = @LanguageID)
BEGIN
RETURN CAST(0ASbit)
END
IF @TranslatorID IS NULLAND @LanguageID IS NOT NULLBEGIN
RETURN CAST(0ASbit)
END
IF @TranslatorID IS NOT NULLAND @LanguageID IS NULLBEGIN
RETURN CAST(0ASbit)
END
IF @TranslatorID IS NOT NULLAND @LanguageID IS NOT NULLAND NOT EXISTS (SELECT*FROM TranslatorsLanguages WHERE TranslatorID = @TranslatorID AND LanguageID = @LanguageID)
BEGIN
RETURN CAST(0ASbit)
END
RETURN CAST(1ASbit)
END
Wyliczenie wolnych miejsc na dany kierunek studiów
CREATEFUNCTIONHowManyStudyVacancies(@StudiesID int)
RETURNS intASBEGIN
DECLARE @MaximumCapacity int;
SELECT @MaximumCapacity =dbo.GetMaxStudyCapacity(@StudiesID);
IF @MaximumCapacity IS NULLBEGIN
RETURN @MaximumCapacity
END
DECLARE @CurrentCapacity int;
SELECT @CurrentCapacity =COUNT(*)
FROM Students
WHERE StudentID IN (
SELECTs.StudentIDFROM Students AS s
JOIN StudiesDetails AS sd
ONs.StudentID=sd.StudentIDWHEREsd.StudiesID= @StudiesID);
RETURN @MaximumCapacity - @CurrentCapacity
END
Wyliczenie wolnych miejsc na dany kurs
CREATEFUNCTIONHowManyCourseVacancies(@CourseID int)
RETURNS intASBEGIN
DECLARE @MaximumCapacity int;
SELECT @MaximumCapacity =dbo.GetMaxCourseCapacity(@CourseID);
IF @MaximumCapacity IS NULLBEGIN
RETURN @MaximumCapacity
END
DECLARE @CurrentCapacity int;
SELECT @CurrentCapacity =COUNT(*)
FROM Students
WHERE StudentID IN (
SELECTs.StudentIDFROM Students AS s
JOIN CourseDetails AS cd
ONs.StudentID=cd.StudentIDWHEREcd.CourseID= @CourseID);
RETURN @MaximumCapacity - @CurrentCapacity
END
Obliczenie łącznej wartości zamówienia
CREATEFUNCTIONGetOrderValue(@OrderID int)
RETURNS moneyASBEGIN
DECLARE @StudiesSum money
DECLARE @StudyMeetingsSum money
DECLARE @CoursesSum money
DECLARE @WebinarsSum moneySELECT @StudiesSum = ISNULL(SUM(s.StudiesEntryFeePrice), 0)
FROM Studies AS s
JOIN OrderStudies AS os ONs.StudiesID=os.StudiesIDJOIN OrderDetails AS od ONos.OrderDetailsID=od.OrderDetailsIDWHEREod.OrderID= @OrderID
SELECT @StudyMeetingsSum = ISNULL(SUM(sm.MeetingPrice), 0)
FROM Studies AS s
JOIN Subject AS su ONs.StudiesID=su.StudiesIDJOIN StudyMeeting AS sm ONsu.SubjectID=sm.SubjectIDJOIN OrderStudies AS os ONs.StudiesID=os.StudiesIDJOIN OrderDetails AS od ONos.OrderDetailsID=od.OrderDetailsIDWHEREod.OrderID= @OrderID
SELECT @CoursesSum = ISNULL(SUM(c.CoursePrice), 0)
FROM Courses AS c
JOIN OrderCourse AS oc ONc.CourseID=oc.CourseIDJOIN OrderDetails AS od ONoc.OrderDetailsID=od.OrderDetailsIDWHEREod.OrderID= @OrderID
SELECT @WebinarsSum = ISNULL(SUM(w.WebinarPrice), 0)
FROM Webinars AS w
JOIN OrderWebinars AS ow ONw.WebinarID=ow.WebinarIDJOIN OrderDetails AS od ONow.OrderDetailsID=od.OrderDetailsIDWHEREod.OrderID= @OrderID
SELECT @StudyMeetingsSum = @StudyMeetingsSum +
ISNULL(SUM(sm.MeetingPrice* (1+s.PriceIncrease)), 0)
FROM StudyMeeting AS sm
JOIN OrderStudyMeeting AS osm ONsm.StudyMeetingID=osm.StudyMeetingIDJOIN OrderDetails AS od ONosm.OrderDetailsID=od.OrderDetailsIDJOIN Subject AS su ONsm.SubjectID=su.SubjectIDJOIN Studies AS s ONsu.StudiesID=s.StudiesIDWHEREod.OrderID= @OrderID
RETURN @StudiesSum + @CoursesSum + @WebinarsSum + @StudyMeetingsSum
END