While loop in SQL Server 2008

In this post, we will discuss how to use while loop in SQL server 2008.

New to Office 365 SharePoint Online? Get Office 365 Enterprise E3 Subscription & Try out all the features

Also, you can check out my previous posts on

Difference between primary key and unique key in SQL Server,

Difference between primary key and foreign key in SQL server 

Like operator examples in SQL Server 2008.

Below is the syntax to use While Loop in SQL Server:


SET @flag = 0

WHILE @flag <= 5


SET @flag = @flag + 1

PRINT ‘You are in ‘ + CAST (@flag AS NVARCHAR(10)) +’ Loop’


The out put will come as shown in the figure below.

Check out Best Alternative to InfoPath -> Try Now


(Installation & Features)

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →