sql - A cursor with the name 'cursor_name' does not exist -


i have code uses nested cursors. when parse it, sql studio tells me "command(s) completed successfully," whenever execute, bunch of repeated "a cursor name 'cursor_stats' not exist." error message displays every line cursor_stats mentioned in, repeats many times. idea problem is?

declare @dc_grp varchar(50) declare @reqt_id int  declare cursor_pairs cursor  select distinct dc.dc_grp, dcx.reqt_id  dc_grp dc inner join       dc_grpx dcx on dc.dc_grp = dcx.dc_grp inner join       reqt req on dcx.reqt_id = req.reqt_id dc.calc_stddev = 1 , req.v_a = 'v' , dcx.stddev_last_update != convert(datetime, convert(int, getdate())) order dc.dc_grp, dcx.reqt_id  -------------------------------------- declare @vavg float declare @vstddev float  declare cursor_stats cursor  select avg(r.[var]), stdev(r.[var])  results r inner join       instance on r.inst_id = i.inst_id  i.dc_grp = @dc_grp , r.reqt_id = @reqt_id , r.[var] != 0 , r.inst_id in            (           select top 100 inst_id           results           reqt_id = @reqt_id           order inst_id desc           )  ---------------------------------------  open cursor_pairs    fetch next cursor_pairs @dc_grp, @reqt_id    while @@fetch_status = 0    begin      open cursor_stats         fetch next cursor_stats @vavg, @vstddev         while @@fetch_status = 0         begin           print @dc_grp + ' ' + @reqt_id + ' ' + @vavg + ' ' + @vstddev         fetch next cursor_stats @vavg, @vstddev         end      close cursor_stats      deallocate cursor_stats    fetch next cursor_pairs @dc_grp, @reqt_id    end close cursor_pairs deallocate cursor_pairs 

you should not deallocate cursor_stats inside loop.

http://msdn.microsoft.com/en-us/library/ms188782.aspx

only after processing finished


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -