In this article, we will explore the essential topic of loops in programming languages, this time focusing on SQL Server with examples. In programming languages, there are various loops available to print values in a specific range with a specific pattern. One of these loops is the While loop. To elaborate further, it operates on the principle of "Proceed until a certain condition is met, and perform these actions while progressing. When the condition is met, end the process." Let's now look at the usage format: WHILE (Desired End Point) BEGIN // Perform operations with values that meet the specified conditions; END Example 1 DECLARE @COUNTER INT = 0 WHILE @COUNTER BEGIN PRINT @COUNTER SET @COUNTER = @COUNTER + 1 END Output of Example 1 Example 2 DECLARE @COUNTER INT = 500 WHILE @COUNTER > 40 BEGIN PRINT @COUNTER SET @COUNTER = @COUNTER - 60 END Output of Example 2 Example 3 DECLARE @Text VARCHAR(50) = 'THIS ARTICLE IS QUITE NICE' DECLARE @CharacterCount INT = LEN(@Text) DECLARE @COUNTER INT = 0 WHILE @COUNTER BEGIN PRINT SUBSTRING(@Text, @COUNTER, 1) SET @COUNTER = @COUNTER + 1 END Output of Example 3 Rich in loop adventures. Source: https://www.ontedi.com/sql/sql-examples-of-while-loop-in-sql-server