• The example coding in the SQL Cursor SP is incorrect as it displays the last record twice. This is really bad programming in that the fetch status should be checked immediately after it is retrieved in order to exit the loop:

    declare @OK bit

    -- Get first row

    open mycursor /*get row values*/

    set @OK = 1;

    while @OK = 1

    BEGIN

    /*get row values*/

    FETCH MyCursor

    INTO @CompName, @ContName

    if @@fetch_status <> 0

    set @OK=0

    else

    begin

    /*perform operations with single row*/

    PRINT 'T_SQL cursor row | ' + @ContName + ' | ' + @CompName

    end

    END