Programming in MS SQL Server 2012 |
WHILE StatementWHILE statement is used to define sets of conditions for the repeated execution of an SQL statement or statement block. The statements are executed repeatedly as long as the specified condition is TRUE. The execution of statements in the WHILE loop can be controlled from inside the loop with the BREAK and CONTINUE keywords. Syntax --
Syntax -- WHILE Boolean_expression
{ sql_statement | statement_block | BREAK | CONTINUE } --
Example 86 -- DECLARE @Number int SET @Number = 1 WHILE @Number < 5
BEGIN
SELECT @Number
SET @Number = @Number + 1
END |
* * * * *