光标永远重复第一个记录

Cursor is repeating first record forever

有人可以告诉我我的代码有什么问题吗?我只是想遍历带有 2 条记录的 table 并将其获取到 return 2 条记录。但正如您在下图中看到的那样,它一直重复第一条记录(永远,直到我点击取消)。谢谢

   SET NOCOUNT ON -- Improves performance by not returning number of rows affected

--General Variables
DECLARE @ImportGUID uniqueidentifier =NEWID() -- Declares and sets a new Unique number. Can be used to remove records at a later stage

--Cursor Variables
DECLARE @FirstNameVariable varchar(50)
DECLARE @SurnameVariable varchar(50)

PRINT 'Starting import ' + CONVERT(varchar(255), @ImportGUID); --just display this on the screen

--Declare the first cursor which will loop through a table collecting data
DECLARE NewPersonTableImportCursor CURSOR FOR
SELECT Firstname, Surname 
from dbo.A_NewPersonTable

--Open NewPersonTableImportCursor
OPEN NewPersonTableImportCursor
--Start looping through the data and updating the cursor variables with data from this cursor
FETCH NEXT FROM NewPersonTableImportCursor INTO @FirstNameVariable, @SurnameVariable
WHILE @@FETCH_STATUS=0 --Fetch Status 0 means successfull so only proceed on those rows from source table that were successfull
BEGIN

PRINT @FirstNameVariable;
END
CLOSE NewPersonTableImportCursor

循环结束前添加FETCH NEXT FROM NewPersonTableImportCursor INTO @FirstNameVariable, @SurnameVariable得到下一条记录