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
 General SQL Server Forums
 New to SQL Server Programming
 Sql Fetch help

Author  Topic 

MichaelMackey
Starting Member

1 Post

Posted - 2009-01-02 : 20:19:17
So I was trying to learn how to use the Fetch command in SQL. But right now I seem to be stuck in an infinite loop. Can anyone see what I'm doing wrong please?

ALTER Procedure [dbo].[Question_LookupByEssayName]
@EssayName varchar(100)
AS
Begin
DECLARE @EssayID VARCHAR(10)

DECLARE QuestionCursor CURSOR FOR
SELECT EssayID FROM Essay WHERE EssayName = @EssayName

OPEN QuestionCursor

FETCH NEXT FROM QuestionCursor INTO @EssayID
WHILE @@FETCH_STATUS = 0
BEGIN

update essaypoint set pointstart = 1

END
FETCH NEXT FROM QuestionCursor INTO @EssayID

CLOSE QuestionCursor
DEALLOCATE QuestionCursor
End

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2009-01-02 : 22:01:22
put the fetch statement within the begin-end block like:

BEGIN
update essaypoint set pointstart = 1
FETCH NEXT FROM QuestionCursor INTO @EssayID
END

if you were not doing this to learn cursors and fetch command, there would be no need to use a cursor in this case.

Go to Top of Page
   

- Advertisement -