Tag Archives: SQL

Basic Layout of Cursor in SQL Server

DECLARE
    @id int,
    @fname varchar(100),

DECLARE mycursor CURSOR READ_ONLY
FOR SELECT id, fname
FROM Employees
WHERE isActive = 1

OPEN mycursor

FETCH NEXT FROM mycursor
INTO @id, @fname

WHILE @@FETCH_STATUS = 0
BEGIN

    print(@fname)

    FETCH NEXT FROM mycursor
    INTO @id, @fname

END

CLOSE mycursor
DEALLOCATE mycursor
Advertisements