By creating a loop, we can perform certain operations as long as this loop continues.
We can use While Loop as follows. As long as @testvariable is less than 10, operations within the BEGIN and END blocks in the WHILE block will be executed repeatedly.
DECLARE @testvariable int=1
To use While Loop with a Cursor, I suggest you read the article “Cursor Usage in SQL Server“.