T-SQL 101: 100 Creating loops in T-SQL with WHILE
Most programming languages have some way of forming loops. Now some of them have a variety. For example, a language like Basic or Excel had a For Next loop, a Do While loop, a While Until loop, etc.
In T-SQL, while you could conceivably construct loops manually by using a GOTO statement, no-one does that and it would be considered a bad idea.
Instead, we form all the loops we need by using a WHILE statement. It can be used to create all the variety of loops mentioned above.
2025-01-27