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. 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
May be interested
- GOTO command in SQL Serverthe goto command is a simple jump command, which allows an unconditional jump program from goto to a location in the program that has a label (laber) command in the same function.
- Instructions for installing SQL Server 2019on september 24, microsoft announced the release of sql server 2019 community technical preview (ctp) 2.0. it is very suitable for database professionals to keep up with modern technology.
- WHILE loop in SQL Serverthe while loop is used if you want to run a code repeatedly when the given condition returns true. let's find out how to use while in sql server with network administrator.
- FOR loop in SQL Serverthe for loop is often used to run a code repeatedly for the number of repetitions. however, in sql server there is no for loop.
- ASCII function in SQL Serverthe article will explore and guide you how to use the ascii () function in sql server.
- CHAR function in SQL Serverchar function in sql server is used to convert an integer expression into the corresponding character in ascii code.