Avatar of brgdotnet
brgdotnet
Flag for United States of America asked on

SImple curosr appears stuck in infinite loop.

SET NOCOUNT ON;

DECLARE @ssn char(9)
DECLARE @Code char(3)
DECLARE @DateEntered char(9)


Hello, I have a simple table with three columns. The table only has like 6 records in it at this time. All I want to do is to read the contents of the table into a cursor, and then dump out the data. I am running the below script from query analyzer, but it appears to be stuck in an infinite loop. Can someone look at my cursor code, and tell me if it is broken?


PRINT '--------  Report --------';

DECLARE people_cursor CURSOR FOR
SELECT SSN, Code,DateEntered
FROM People
ORDER BY DateEntered;

OPEN people_cursor

FETCH NEXT FROM people_cursor
INTO @ssn, @Code, @DateEntered

WHILE @@FETCH_STATUS = 0
BEGIN

      PRINT @ssn
      PRINT @Code
      PRINT @DateEntered

    CLOSE people_cursor
    DEALLOCATE people_cursor

END
Microsoft SQL Server

Avatar of undefined
Last Comment
brgdotnet

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Éric Moreau

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
brgdotnet

ASKER
Thank you Eric,

I am just now learning about cursors.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck