How to pass a list of parameters from a table variable?

  • 1. I have a stored procedure that takes a list of parameters and generates some output.

    exec gradeClass classID, studentIDs

    2. I have another stored procedure that generates a list of students in the table variable

    @tableClasses:

    classID studentIDs

    1 1,2,3,4,5

    2 1,2

    3 6,7

    After @tableClasses is generated, I need to send each row of this table one by one as a list of parameters to the gradeClass stored procedure for some calculations.

    How can I send those parameters?

    Thank you..

  • Search this site for the SPLIT function...

    ______________________________________________________________________

    Personal Motto: Why push the envelope when you can just open it?

    If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.

    Jason L. Selburg
  • Greetings,

    Maybe this might be a way to get your records to the second procedure.

    DECLARE @HldClassID int

    DECLARE @HldStudentID int

    DECLARE ClassesCursor CURSOR LOCAL READ_ONLY FOR

    SELECT

    ClassID,

    StudentID

    FROM @TableClasses

    OPEN ClassesCursor

    FETCH NEXT FROM ClassesCursor

    INTO

    @HldClassID,

    @HldStudentID

    WHILE @@FETCH_STATUS = 0

    BEGIN

    EXEC GradeClass @HldClassID, @HldStudentID

    FETCH NEXT FROM ClassesCursor

    INTO

    @HldClassID,

    @HldStudentID

    END

    CLOSE ClassesCursor

    DEALLOCATE ClassesCursor

    This may give you some help in finding a solution to your problem.

    Have a good day.

    Terry Steadman

  • Search this site for "Tally table". You will find a great article by Jeff Moden which shows a solution exactly for this requirement without any cursors. 😉

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply