Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. cursor goes in to infinit loop.........

cursor goes in to infinit loop.........

Scheduled Pinned Locked Moved Database
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pranavcool
    wrote on last edited by
    #1

    hi, I have written a cursor that goes into infinite loop. I am not able to make out where i have done wrong. the following is the code. /******************************************************************************/ declare @dirid int declare @topic varchar(8000) create table #topic(Dir_Id int,topic_Id varchar(1000)) insert into #topic(Dir_Id,topic_Id)select D.Dir_Id,D.topicid FROM Category CN INNER JOIN directory D ON CN.Cat_Id = D.OrgType_Id INNER JOIN SubCategory SB ON D.Country = SB.SubCat_ID WHERE CN.Cat_Name = 'Academic' declare curtopic cursor for select Dir_Id,topic_Id from #topic open curtopic fetch next from curtopic into @dirid,@topic begin while @@fetch_status = 0 set @topic = '' SELECT @topic = topic_Id from #topic fetch next from curtopic into @dirid,@topic end close curtopic deallocate curtopic print @topic drop table #topic /****************************************************************************/ i want to retrieve the data row by row for which i have written cursor. but it is going in to infinite loop. any help would be great full. regards, pranav

    Pranav Dave

    R 1 Reply Last reply
    0
    • P pranavcool

      hi, I have written a cursor that goes into infinite loop. I am not able to make out where i have done wrong. the following is the code. /******************************************************************************/ declare @dirid int declare @topic varchar(8000) create table #topic(Dir_Id int,topic_Id varchar(1000)) insert into #topic(Dir_Id,topic_Id)select D.Dir_Id,D.topicid FROM Category CN INNER JOIN directory D ON CN.Cat_Id = D.OrgType_Id INNER JOIN SubCategory SB ON D.Country = SB.SubCat_ID WHERE CN.Cat_Name = 'Academic' declare curtopic cursor for select Dir_Id,topic_Id from #topic open curtopic fetch next from curtopic into @dirid,@topic begin while @@fetch_status = 0 set @topic = '' SELECT @topic = topic_Id from #topic fetch next from curtopic into @dirid,@topic end close curtopic deallocate curtopic print @topic drop table #topic /****************************************************************************/ i want to retrieve the data row by row for which i have written cursor. but it is going in to infinite loop. any help would be great full. regards, pranav

      Pranav Dave

      R Offline
      R Offline
      Rob Philpott
      wrote on last edited by
      #2

      pranavcool wrote:

      while @@fetch_status = 0 set @topic = ''

      There you have it - that's the loop that executes. You need to put the statements in a block using begin and end.

      Regards, Rob Philpott.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups