Added cursor example

This commit is contained in:
Chris Glavan 2023-10-03 11:36:17 -04:00
parent 9b74d34bde
commit 2471c47b2f

21
Cursor.sql Normal file
View File

@ -0,0 +1,21 @@
--Declare any variables needed for the cursor query
DECLARE @id uniqueidentifier
DECLARE @name varchar(max)
DECLARE db_cursor CURSOR FOR
--SELECT Id, Name FROM Table WHERE Field = value
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @id
WHILE @@FETCH_STATUS = 0
BEGIN
--Select/update/delete statements go here
FETCH NEXT FROM db_cursor INTO @id
END
CLOSE db_cursor
DEALLOCATE db_cursor