Lesson 32. Looping

You can process in loops using the WHILE statement. In twenty years, I think I have used WHILE ONCE. I can usually find a better solution than using WHILE.

Examples

Incrementing An Index Value

In [ ]:

USE demo

DECLARE @i TINYINT = 1

WHILE @i < 10 BEGIN
PRINT 'The variable''s value is ' + CAST(@i AS NVARCHAR(1)) + '.'
SET @i = @i + 1
END

Last updated