Home > DeveloperSection > Interviews > How to use while loop in sql server?

Posted on    January-19-2012 1:36 AM

 MSSQL Server MSSQL Server 
Ratings:
 1 Answer(s)
  2287  View(s)
Rate this:

Amit Singh

Total Post:565

Points:2825
Posted on    January-19-2012 1:00 AM

----------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

Don't want to miss updates? Please click the below button!

Follow MindStick