Aan de slagGa gratis aan de slag

Creating a WHILE loop

In this exercise, you will use the variable you created in the previous exercise you write a WHILE loop. Recall that structure:

WHILE some_condition 

BEGIN 
    -- Perform some operation here
END

Deze oefening maakt deel uit van de cursus

Intermediate SQL Server

Cursus bekijken

Oefeninstructies

Write a WHILE loop that increments counter by 1 until counter is less than 30.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

DECLARE @counter INT 
SET @counter = 20

-- Create a loop
___

-- Loop code starting point
___
	SELECT @counter = @counter + 1
-- Loop finish
___

-- Check the value of the variable
SELECT @counter
Code bewerken en uitvoeren