?
Solved

Cursor loop problem maybe to do with @@FETCH_STATUS

Posted on 2000-05-15
3
Medium Priority
?
645 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 200 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

741 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