BREAK (Control Interrupt) command in SQL Server
The Break command used to exit the loop does not specify a stop condition or you want to stop the loop on condition that you specify and execute the statements following the END command of the loop.
Syntax
To use the command to interrupt BREAK control in SQL Server, we use the following syntax:
BREAK;
There are no parameters and arguments in the BREAK statement.
Note:
- You use BREAK to end the WHILE loop early.
- If in the code there is WHILE nested LOOP, BREAK will terminate the nearest WHILE loop.
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;
END
PRINT @Total;
GO
In this example using the BREAK statement, the WHILE loop will end when @Number reaches value 5.
Previous article: FOR loop in SQL Server
Next lesson: CONTINUE command in SQL Server
3.8 ★ | 5 Vote
You should read it
- What happens when we break our fingers 'cracked'?
- How to Break a Chain
- Page break in Word - Instructions on how to break a page in Word 2007, 2010, 2013, 2016
- Out of love but afraid to express? Don't worry, there's Breakup Shop
- How to break Excel Password without software
- Word 2013 full-text tutorial (Part 12): How to break pages, paragraph breaks
- How to crack Windows 10 password, how to break password on Windows 10
- No need to be a singer, you can still smash a glass of water with singing
May be interested
- The sfc command in Windows(applies to windows server (semi-annual channel), windows server 2016, windows server 2012 r2, windows server 2012)
- CASE statement in SQL Serverthis article will show you in detail how to use the case statement handling function in sql server with specific syntax and examples to better visualize and capture functions.
- SELECT TOP command in SQL Serverin sql server, the select top command is used to retrieve records from one or more tables in sql server and limit the number of return records based on a fixed value or percentage.
- SELECT INTO command in SQL Serverthe article guides using select into command in sql server with syntax and examples.
- Hackers break into WordPress serversan unidentified hacker hacked into the wordpresss server and installed a remote control trojan and download versions of this widely used blog application.
- Control loop in Unix / Linuxthe previous chapter has been shown how to create loops and work with them to perform various tasks. sometimes you need to stop a loop or continue their repetitive process.
- Prncnfg command in Windows(applies to windows server (semi-annual channel), windows server 2016, windows server 2012 r2, windows server 2012
- Manage the Event Log with the command linefor many of us, using the command line - command line to control and use some of the functions in the windows system will cause them to have headaches and problems. however, if you have to set up an automatic function system in windows and other server operating systems, the command line is an irreplaceable tool ...
- Moving a website to a new server does not interrupt accessin this article, we will show you how to transfer your website to a new server easily without interrupting the website's access.
- The command bootcfg delete in Windowsthe bootcfg delete command deletes the operating system entry in the [operating systems] section of the boot.ini file. the command applies to: windows server (semi-annual channel), windows server 2016, windows server 2012 r2, windows server 2012.