fetch next from TermResultCursor into
@CourseId
while @@FETCH_STATUS = 0
begin
declare ClassTestResult cursor for

SELECT StudentId, SUM(ClassTestMarks) —- make sum of 3/4 class test
FROM dbRegistration.dbo.T_Term_Class_Test_Marks
WHERE CourseId = @CourseId
GROUP BY StudentId

open ClassTestResult

fetch next from ClassTestResult into
@StudentId, @TotalMarks
while @@FETCH_STATUS = 0
begin
UPDATE T_Term_Std_Result_Theory_Details
SET ClassTest=@TotalMarks
WHERE StudentId=@StudentId AND CourseId=@CourseId AND TermId = @TermId

fetch next from ClassTestResult into
@StudentId, @TotalMarks
end
close ClassTestResult
deallocate ClassTestResult

fetch next from TermResultCursor into
@CourseId
end
close TermResultCursor
deallocate TermResultCursor

— If Any errors then go for Roll Back Transaction
SELECT @intErrorCode = @@ERROR
IF (@intErrorCode <> 0) GOTO PROBLEMERROR

fetch next from TermTheoryResultCursor into
@CourseId, @StudentId, @TotalMarks
while @@FETCH_STATUS = 0
begin
SELECT @LetterGrade=LetterGrade, @GradePoint=GPA
FROM T_Term_Marks_GPA_Setup
WHERE StartMarks<=@TotalMarks AND @TotalMarks<=EndMarks AND TermId=@TermId

fetch next from TermSessionalResultCursor into
@CourseId, @StudentId, @TotalMarks
while @@FETCH_STATUS = 0
begin
SELECT @LetterGrade=LetterGrade, @GradePoint=GPA
FROM T_Term_Marks_GPA_Setup
WHERE StartMarks<=@TotalMarks AND @TotalMarks<=EndMarks AND TermId=@TermId

SELECT DISTINCT @PrevTerm=TermId,@PrevCourse=CourseId FROM T_Term_Std_ThesisProject_Result_Details WHERE TermId<>@TermId AND StudentId=@StudentId
AND ResultPrecessingStatus=0 AND CourseContinuityStatus=’X’

IF (@CourseType=’Theory’)
begin
Insert into T_Term_Std_Result_Theory_Details(StudentId,TermId,CourseId,CourseTitle)
values(@StudentId,@TermId,@CourseId,@CourseTitle)
end
ELSE IF (@CourseType=’Thesis’)
begin
Insert into T_Term_Std_ThesisProject_Result_Details(StudentId,TermId,CourseId)
values(@StudentId,@TermId,@CourseId)
end

ELSE IF(@CourseType<>’Theory’ AND @CourseType<>’Thesis’)
begin
Insert into T_Term_Student_Result_Lab_Details(StudentId,TermId,CourseId)
values(@StudentId,@TermId,@CourseId)
end

SELECT @intErrorCode = @@ERROR
IF (@intErrorCode <> 0) GOTO PROBLEMERROR — If Any errors then go for Roll Back Transaction