Solved

Cursor loop problem maybe to do with @@FETCH_STATUS

Posted on 2000-05-15
3
616 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
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 142

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL profiler equivalent in MS-Access 3 44
sql server query from excel 3 57
Extract string portion 2 14
SQL - insert empty rows into output results 11 25
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

895 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

13 Experts available now in Live!

Get 1:1 Help Now