I want to reference the nth row of the #temptable (at the second SQL comment is below). What expression will allow me to do so?
DECLARE @counter INT
SET @counter = 0
WHILE (@counter<count(#temptable))
--#temptable has one column and 0 or more rows
BEGIN
DECLARE @variab INT
EXEC @variab = get_next_ticket 3906, 'n', 1
INSERT INTO Student_Course_List
SELECT @student_id,
-- nth result set row in #temptable, where n is @count+1
@variab
SET @counter = @counter +1
END
Cursor (will this work?):
for record in (select id from #temptable) loop
--For statements, use record.id
end loop;
Instead of using a while loop (with a counter like you are doing) to iterate the table you should use a cursor
Syntax would be: