How do I use the results of a stored procedure from within another?

后端 未结 4 415
有刺的猬
有刺的猬 2020-12-19 00:54

I have a stored procedure that I want to call from within another, and then loop through the results. Sort of like using a cursor with a stored procedure rather than a SQL s

4条回答
  •  旧时难觅i
    2020-12-19 01:01

    What Justin pointed out is what you have to do, but instead of doing

    while @counter < (select max(idx) from @temp)
    

    do this

    declare @maxid int
    select @maxid = max(idx), @counter = 1
    from @temp
    while @counter < @maxid begin
    -- go on
      set @counter = @counter + 1
    end
    

    Also, if declaring the table as @temp doesn't work you could declare it as #temp.

提交回复
热议问题