Skip to content

Instantly share code, notes, and snippets.

@nikanos
Last active November 29, 2022 17:07
Show Gist options
  • Save nikanos/159340ff4102599c34c19dd8339195a2 to your computer and use it in GitHub Desktop.
Save nikanos/159340ff4102599c34c19dd8339195a2 to your computer and use it in GitHub Desktop.
SQL Server TSQL Loop example
DECLARE @cnt INT = 0;
WHILE @cnt < 10
BEGIN
PRINT 'Doing Something in loop #' + Convert(VARCHAR(10),@cnt);
--Use RAISEERROR to flush PRINT buffer
RAISERROR(N'', --message
0, --severity
1) --state
WITH NOWAIT;
WAITFOR DELAY '00:00:01';
SET @cnt = @cnt + 1;
END;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment