CONTINUE command in SQL Server
The CONTINUE command is used to give command execution authority to the last expression of the loop. That means upside-down to the top of the loop, all the commands that follow in the loop containing CONTINUE will be ignored without execution.
The CONTINUE command is used to give command execution authority to the last expression of the loop. That means upside-down to the top of the loop, all the commands that follow in the loop containing CONTINUE will be ignored without execution. This article will detail how to use this command in SQL Server.
Syntax
To use the CONTINUE statement in SQL Server, we use the following syntax:
TIẾP TỤC;
Note:
- There are no parameters and arguments in the CONTINUE statement.
- You use the CONTINUE statement to return to the WHILE loop and execute its subsequent conditions.
For example
DECLARE @Number INT = 1;
DECLARE @Total INT = 0;
@Number WHILE <= 10
BEGIN
IF @NUMBER = 5
BREAK;
ELSE
SET @Total = @Total + @Number;
SET @Number = @Number + 1;
TIẾP TỤC;
END;
END;
PRINT @Total;
GO
In this example using the CONTINUE statement, we will restart the WHILE loop if the variable @NUMBER is different from 5 as specified by the IF . ELSE statement.
Previous article: BREAK (Control Interrupt) command in SQL Server
Next lesson: GOTO command in SQL Server
4 ★ | 1 Vote
You should read it
- Control loop in Unix / Linux
- Break and continue commands in Python
- BREAK (Control Interrupt) command in SQL Server
- CASE statement in SQL Server
- GOTO command in SQL Server
- New malware uses Google Drive as a command-and-control server
- Setlocal command in Windows
- Freedisk command in Windows
- The cacls command in Windows
- USER_NAME function in SQL Server
- COALESCE statement in SQL Server
- CASE function in SQL Server (part 1)