Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 cursor help

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2009-01-18 : 05:18:06
[code]DECLARE sob CURSOR FOR

select useritemsboughtid,userid from useritemsbought where closeddate is null and soamount>=5000


OPEN sob
FETCH sob INTO @useritemsboughtid,
@userid

WHILE @@Fetch_Status = 0

BEGIN



exec admincalculategain @useritemsboughtid,@userid
END

CLOSE sob

DEALLOCATE sob

RETURN[/code]

this is running an enless loop - what am i doing wrong?

xpandre
Posting Yak Master

212 Posts

Posted - 2009-01-18 : 08:45:56
[code]OPEN sob
FETCH sob INTO @useritemsboughtid,
@userid

WHILE @@Fetch_Status = 0

BEGIN



exec admincalculategain @useritemsboughtid,@userid
FETCH sob INTO @useritemsboughtid,
@userid

END

CLOSE sob

DEALLOCATE sob

RETURN[/code]

else how would @@Fetch_Status = 0 ever go!!!!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-18 : 08:53:18
you're fetching next value from cursor that why...you need a FETCH NEXT at end of loop before closing to get next record value from table.
why are you trying to execute procedure for each value row by row? whats the procedure doing?
Go to Top of Page
   

- Advertisement -