Loop In Store Procedure

While Loop:

 

In store procedure only one loop is assigned.which is While Loop.

 

What is Loop?

A loop is a sequence of instruction s that is continually repeated until a certain condition is reached. Typically, a certain process is done

 

WHILE LOOP

A while loop will check the condition first and then executes the block of Sql Statements within it as along as the condition evaluates to true.


Syntax:


WHILE Condition


BEGIN


Sql Statements


END

 

Example:

DECLARE @loop INT

SET @loop = 0

WHILE @loop <= 10

BEGIN  

SET @loop = @loop + 1  

PRINT @loop

END

 

Result:

1

2

3

4

5

6

7

8

9

10

11