Here Mudassar Ahmed Khan has explained with an example, how to use WHILE LOOP in SQL Server (Transact-SQL).
The WHILE statement as used in various programming languages works in similar way in SQL Server. It is a control flow statement and it is used to perform iterations until the condition holds TRUE.