Added cursor example
This commit is contained in:
parent
9b74d34bde
commit
2471c47b2f
21
Cursor.sql
Normal file
21
Cursor.sql
Normal 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
|
Loading…
x
Reference in New Issue
Block a user