SQL Server: CONTINUE Statement

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 statements in SQL Server (Transact-SQL) is:

CONTINUE;

Parameters or Arguments

There are no parameters or arguments for the CONTINUE statements.

Note

  • You use the CONTINUE statements 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 statements 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 adglob.in';
      CONTINUE;
   END;

END;

PRINT 'Done WHILE LOOP on adglob.in';
GO

In this CONTINUE statements example, we will restart the WHILE LOOP if the variable @site_value is not equal to 2, as specified by the IF…ELSE statement.

This Post Has 3 Comments

Leave a Reply