From 2471c47b2f642c0f83d77ee351c339ad2fa61589 Mon Sep 17 00:00:00 2001 From: Chris Glavan Date: Tue, 3 Oct 2023 11:36:17 -0400 Subject: [PATCH] Added cursor example --- Cursor.sql | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Cursor.sql diff --git a/Cursor.sql b/Cursor.sql new file mode 100644 index 0000000..a4f0f81 --- /dev/null +++ b/Cursor.sql @@ -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 \ No newline at end of file