HOW TO USE WHILE LOOP IN SQL SERVER?

Amit Singh

Total Post:565

Points:2825
Posted by  Amit Singh
 2564  View(s)
Ratings:
Rate this:
  1. Amit Singh

    Post:565

    Points:2825
    How to use while loop in sql server?

    ----------This is loop example in sql server----------------

    Declare @maxNo int
    Declare @i int
    set @maxNo=4
    set @i=1
    print 'Output'
    ---Use while loop----
    while(@i<=@maxNo)
    begin               
        print @i
        set @i=@i+1
    end           


    --output------
    1
    2
    3
    4

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!