SQL Server: CONTINUE Statement
This SQL Server tutorial explains how to use the CONTINUE statement in SQL Server (Transact-SQL) with syntax and examples.
Description
In SQL Server, the CONTINUE statement is used when you are want a WHILE LOOP to execute again. It will ignore any statements after the CONTINUE statement
Syntax
The syntax for the CONTINUE statement in SQL Server (Transact-SQL) is:
CONTINUE;
Parameters or Arguments
There are no parameters or arguments for the CONTINUE statement.
Note
- You use the CONTINUE statement to restart a WHILE LOOP and execute the WHILE LOOP body again from the start.
- See also the WHILE LOOP and BREAK statement.
Example
Let’s look at an example that shows how to use the CONTINUE statement in SQL Server (Transact-SQL).
For example:
DECLARE @site_value INT; SET @site_value = 0; WHILE @site_value <= 10 BEGIN IF @site_value = 2 BREAK; ELSE BEGIN SET @site_value = @site_value + 1; PRINT 'Inside WHILE LOOP on TechOnTheNet.com'; CONTINUE; END; END; PRINT 'Done WHILE LOOP on TechOnTheNet.com'; GO
In this CONTINUE statement example, we will restart the WHILE LOOP if the variable @site_value is not equal to 2, as specified by the IF…ELSE statement.