How to store sql query in variable
<pre><code>SELECT Staff_Teaching.TeachingID FROM   Staff_Teaching INNER JOIN
          Staff ON Staff_Teaching.StaffID = Staff.StaffID WHERE        (Staff.StaffID = @StaffID) AND (Staff_Teaching.SemesterID = @SemesterID))
</code></pre>

<p>I have this query which return the staff TeachingID which is an id for the courses that the staff teaches.</p>

<p>My question is :</p>

<ol>
<li><p>How to store these values because it returns MORE THAN 1 values , can I use array in sql server or in c# ?</p></li>
<li><p>Then I want to take theses value and pass it to other query as shown below : </p></li>
</ol>

<p>(SELECT Exam.Date  FROM Exam WHERE (ExamID = @GetExamID)</p>

<pre><code>`@GetExamID` is where I want to pass these values to be checked 
</code></pre>

<p>can I use foreach or array? and I am using asp.net (C#)</p>

<p>This is what I am trying to do</p>

<pre><code>BEGIN TRANSACTION
SET @GetTeachingID =(SELECT        Staff_Teaching.TeachingID
FROM          Staff_Teaching INNER JOIN
              Staff ON Staff_Teaching.StaffID = Staff.StaffID
WHERE        (Staff.StaffID = @StaffID) AND (Staff_Teaching.SemesterID = @SemesterID))
COMMIT 

BEGIN TRANSACTION
SELECT  Course_Department.CourseID
FROM            Course_Department INNER JOIN
                         Exam ON Course_Department.CourseID = Exam.ExamID INNER JOIN
                         ExamSchedule ON Exam.ExamID = ExamSchedule.ExamID INNER JOIN
                         Staff_Teaching ON Course_Department.TeachingID = Staff_Teaching.TeachingID
WHERE        (Staff_Teaching.TeachingID = @GetTeachingID)

COMMIT 


BEGIN TRANSACTION
SET @GetExamDate=(SELECT Exam.Date  
FROM Exam
WHERE (ExamID = @GetExamID))
COMMIT 

BEGIN TRANSACTION
SET @GetExamTime=(SELECT Exam.BegainTime  
FROM Exam
WHERE (ExamID = @GetExamID))
COMMIT 

BEGIN TRANSACTION
SELECT        ExamScheduleID
FROM          Exam INNER JOIN
              ExamSchedule ON Exam.ExamID = ExamSchedule.ExamID
WHERE        (ExamSchedule.ExamScheduleID = @ExamScheduleID) AND (Exam.Date LIKE @GetExamDate) AND (Exam.BegainTime&lt;=@GetExamTime)
COMMIT 



END
</code></pre>

<p>I have 5 query the first one will get the teachingid (1 Value)
the second will get the coursesid (More than 1 value)
then next two will take coursesid and get the exam date and time 
then l want to check if there are any result in the last query   </p>