Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Updating Cursor with Replace Command
Message
From
25/09/2017 08:21:42
 
 
To
21/09/2017 17:39:17
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 8.1
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01654486
Message ID:
01654539
Views:
93
>Dear Sir,
>I am using the following code to update a Row Position (POSR) in a Cursor
>
>Select Distinct POSR From PAGETWO Order By POSR Desc Into Cursor DISTINCTPOSR
>				nCD=12
>					Scan
>					nPagetwoDistinctposR=POSR
>					Select PAGETWO
>					nCOMMONDIFFERENCE=m.T-nCD
>					Replace All POSR With nCOMMONDIFFERENCE For POSR=nPagetwoDistinctposR
>					Select DISTINCTPOSR
>					nCD=nCD+12
>				ENDSCAN
>
>
>Using the above code at first instance my POSR is changed by Desired value say from 696 to 453.
>
>However, In the scan loop if the value of nPagetwoDistinctposR again comes to 453 by chance, it again updates my cursor to new value.
>
>For the above I have a solution to insert another Like Yes/NO etc but I am seeking for some simple solution and Better Code or a SQL that may work faster For the above.

I'm confused. Why are you doing REPLACE ALL in a loop? Normally, you'd do one or the other. I think you're looping on the cursor you just created, but even so, that's what's causing you to replace some records more than once.

It doesn't look like your calculation is that complicated. Can't you just use SQL UPDATE with a join between the cursor and the original table to indicate which record in the cursor affects which record in the original table and do the whole thing in one command, something like:
UPDATE PageTwo ;
  FROM DistinctPosR ;
  SET PosR = m.nT - (m.CD * ImNotSureWhatHere);
  WHERE PageTwo.PosR =  DistinctPosR.PosR
I'm not sure how you get your multiplier in because I don't understand the underlying problem, but you may be able to do it.

If you can't do that, your best bet is to use another cursor to hold the new value for each record as you compute it and then do a single REPLACE ALL at the end of the loop.

Tamar
Previous
Reply
Map
View

Click here to load this message in the networking platform