tkue
6/14/2017 - 8:03 PM

Boiler plate template for cursor

Boiler plate template for cursor

DECLARE @varname NVARCHAR(MAX)

DECLARE cur CURSOR LOCAL STATIC FORWARD_ONLY
FOR
    SELECT var
    FROM dbo.TableName
    INTO
        @varname

OPEN cur

FETCH NEXT
FROM cur
INTO
    @varname

WHILE @@FETCH_STATUS = 0:
BEGIN


    nextrow:
    FETCH NEXT
    FROM cur
    INTO
        @varname

END
CLOSE cur
DEALLOCATE cur