cursor goes in to infinit loop.........
-
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
-
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
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
andend
.Regards, Rob Philpott.