While loop in Sql

In this lesson we are going to learn,how to create while loop in sql.Loops help us to do iterative work very effectively.So we need to know about it.

While Loop

Syntax

 while(condition )
begin
increment
end

Example
declare @cnt int,@test int

               set @test =10
               set @cnt =2

        while(@cnt <=@test )
               begin
                   select @cnt,@test 
                   set @cnt =@cnt+1
          end

It looks very simple but often we are confusing to do it.

Comments

Popular posts from this blog

Types of Architects

Basic measurements

Search html table contents based on its td using Jquery