Solved

Cursor loop problem maybe to do with @@FETCH_STATUS

Posted on 2000-05-15
3
640 Views
Last Modified: 2008-01-16
Hi Guys

Perhaps one of you could tell me why I seem to have an endless loop in this code. I've been sat staring at it for ages but can't see anything wrong.

WHILE @@FETCH_STATUS=0

                    --Retrieve data from PlannerHistory
                    IF EXISTS (SELECT * FROM PlannerHistory WHERE PubNo = @curPubNoHistory AND Period = @pPeriod)
                   
                       BEGIN

                          SELECT @PubName = PubName, @SalesTarget = SalesTarget, @LastYearSales = LastYearSales, @SalesGrowth = SalesGrowth,
                             @BudgetCoreWagePercent = BudgetCoreWagePercent, @CoreWagePercentTarget = CoreWagePercentTarget,
                             @BudgetAmendment = BudgetAmendment, @AmendedCoreWagePercentTarget = AmendedCoreWagePercentTarget,
                             @AveragePayRate = AveragePayRate,  @TotalFixedCosts = TotalFixedCosts, @CalculatedHours = CalculatedHours,
                             @TargetHours = TargetHours, @HoursVariance = HoursVariance, @ForecastCoreWagePercent = ForecastCoreWagePercent,
                             @TotalHours = TotalHours, @IdealManagement = IdealManagement, @CurrentManagers = CurrentManagers, @ManagementGap = ManagementGap
                             FROM PlannerHistory
                             WHERE PubNo = @curPubNoHistory AND Period = @pPeriod

                          --Put the data into a temporary table
                          INSERT #Planner
                             SELECT @curPubNoHistory, @PubName, @SalesTarget, @LastYearSales, @SalesGrowth, @BudgetCoreWagePercent, @CoreWagePercentTarget,
                                @BudgetAmendment, @AmendedCoreWagePercentTarget, @AveragePayRate,  @TotalFixedCosts, @CalculatedHours,
                                @TargetHours, @HoursVariance, @ForecastCoreWagePercent, @TotalHours, @IdealManagement, @CurrentManagers, @ManagementGap
                       END
                               
                --Get the next pub in the cursor
                FETCH PubNumbers
                   INTO @curPubNoHistory
0
Comment
Question by:jgianni
[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
3 Comments
 
LVL 1

Accepted Solution

by:
jboyd earned 50 total points
ID: 2811093
Your fetch next is outside the while loop. Add a BEGIN right after the While statament and an END right after the fetch into statement.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2811110
Confirmation!

I assume however that you also have
-Get the first pub in the cursor
FETCH PubNumbers
INTO @curPubNoHistory
before your WHILE statement
0
 

Author Comment

by:jgianni
ID: 2813718
Thank you very much.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

738 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