Skip to content

Instantly share code, notes, and snippets.

@ArtemAvramenko
Last active December 7, 2017 17:36
Show Gist options
  • Save ArtemAvramenko/64c7cec1b77c62a0cda5409c3c364242 to your computer and use it in GitHub Desktop.
Save ArtemAvramenko/64c7cec1b77c62a0cda5409c3c364242 to your computer and use it in GitHub Desktop.
foreach t/sql
-- for each...
DECLARE @ItemId INT
DECLARE ItemCursor CURSOR FOR
SELECT ItemId
FROM Items
WHERE ...
OPEN ItemCursor
WHILE 1 = 1
BEGIN
FETCH NEXT FROM ItemCursor INTO @ItemId
IF @@FETCH_STATUS <> 0 BREAK
-- ...@ItemId
END
CLOSE ItemCursor
DEALLOCATE ItemCursor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment