hi every body.
i have a stored procedure with a select statment that looped by a cursor .
this is the code
DECLARE res cursor READ_ONLY
for (SELECT DISTINCT GroupNo
FROM ppu_MajorPlan
WHERE (PlanYear =(SELECT majorPlanYear
FROM ppu_Student
WHERE (StudentNo = @StudentNo)))
AND (MajorNo =(SELECT MajorNo
FROM ppu_Student
WHERE (StudentNo = @StudentNo)))
)
/* Using The Curser*/
open res
FETCH NEXT FROM res
INTO @GroupID
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT CourseNo
FROM ppu_Grades
WHERE (StudentNo = @StudentNo) AND (GradeNGrade < 60)
intersect
SELECT CourseNo
FROM ppu_PlanGroupCourse
WHERE (GroupNo =@GroupID)
AND (MajorPlanYear = (SELECT majorPlanYear
FROM ppu_Student
WHERE (StudentNo = @StudentNo)))
AND (MajorNo = (SELECT MajorNo
FROM ppu_Student
WHERE (StudentNo = @StudentNo)))
FETCH NEXT FROM res
INTO @GroupID
END
CLOSE res
DEALLOCATE res
END
the Question is : how can I store and use the data returned from the intersection ,"the problem i faced is that the stored procedure return the result of the first interesction Not all results from the loop"