SQL Server – Cursor Syntax


-- Variables to hold the data
DECLARE @Var1 int
DECLARE @Var2 datetime

-- CURSOR
DECLARE db_cursor CURSOR FOR
SELECT Col1, Col2
FROM Table1

OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @Var1 , @Var2
WHILE @@FETCH_STATUS = 0
BEGIN
    -- DO STUFF HERE

FETCH NEXT FROM db_cursor INTO @Var1 , @Var2 END CLOSE db_cursor DEALLOCATE db_cursor

Leave a Reply

Your email address will not be published. Required fields are marked *