In this post explains how to use the CONTINUE statement in SQL Server (Transact-SQL) with syntax and examples.
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
The syntax for the CONTINUE statement in SQL Server (Transact-SQL) is:
CONTINUE;
There are no parameters or arguments for the CONTINUE statement.
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 AODBA.com';
CONTINUE;
END;
END;
PRINT 'Done WHILE LOOP on AODBA.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.