Solved

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

Posted on 2001-09-05
7
538 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 143

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month11 days, 15 hours left to enroll

623 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