Solved

How to create LOOP STRUCTURE in a stored procedure in SQL Server ?

Posted on 2001-09-05
7
533 Views
Last Modified: 2008-02-01
Hi,
Can anybody suggest me for , how to create LOOP STRUCTURE in a stored procedure in SQL Server? Pl give me example.

Thanx a lot
waiting for reply.
From
Santosh
0
Comment
Question by:SantoshGokhale
7 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6456319
one way is using bookmarks:

 declare @var int
 set @var = 0

LOOP:
  select @var = @var + 1

  -- some code here...

  if @var < 10 GOTO LOOP


Cheers

0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6457130
If you would rather not use GoTo's than the While loop is what you are looking for:

@I = 1
While @I <= 10
   Begin
      ...
      @I = @I + 1
   End

0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 25 total points
ID: 6457641
That should have been:
Set @I = 1
While @I <= 10
  Begin
     ...
     Set @I = @I + 1
  End

Anthony
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Expert Comment

by:prakashbitra
ID: 6458233
can u explain me ur  requirement
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6462925
prakashbitra,

I think the chances that SantoshGokhale will followup are pretty remote, considering his past grading history:

Questions Asked 4
Last 10 Grades Given  
Question Grading Record 0 Answers Graded / 0 Answers Received

All the other questions are from July.

Anthony
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7207643
Hi SantoshGokhale@devx,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Split points between: angelIII and acperkins@devx

SantoshGokhale@devx, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 5

Expert Comment

by:Netminder
ID: 7240973
Per recommendation, force-accepted.

Netminder
CS Moderator

angel111: points for you at http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20341024.html
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now