Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Applies to:
SQL Server
Azure SQL Database
Azure SQL Managed Instance
Azure Synapse Analytics
Analytics Platform System (PDW)
SQL analytics endpoint in Microsoft Fabric
Warehouse in Microsoft Fabric
SQL database in Microsoft Fabric
BREAK exits the current WHILE loop. If the current WHILE loop is nested inside another, BREAK exits only the current loop, and control is given to the next statement in the outer loop.
BREAK is usually inside an IF statement.
Imagine a table where a value is expected when another antecedent process is completed:
WHILE (1=1)
BEGIN
IF EXISTS (SELECT * FROM ##MyTempTable WHERE EventCode = 'Done')
BEGIN
BREAK; -- 'Done' row has finally been inserted and detected, so end this loop.
END
PRINT N'The other process is not yet done.'; -- Re-confirm the non-done status to the console.
WAITFOR DELAY '00:01:30'; -- Sleep for 90 seconds.
END
DECLARE @sleeptimesec int = 1;
DECLARE @startingtime datetime2(2) = getdate();
PRINT N'Sleeping for ' + CAST(@sleeptimesec as varchar(5)) + ' seconds'
WHILE (1=1)
BEGIN
PRINT N'Sleeping.';
PRINT datediff(s, getdate(), @startingtime)
IF datediff(s, getdate(), @startingtime) < -@sleeptimesec
BEGIN
PRINT 'We have finished waiting.';
BREAK;
END
END
Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register today