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
You've just finished reading the article "CONTINUE command in SQL Server" edited by the TipsMake team. You can save continue-command-in-sql-server.pdf to your computer here to read later or print it out. We hope this article has provided you with many useful tech tips and tricks. You can search for similar articles on tips and guides. Thank you for reading and for following us regularly.