Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Matching two cursors
Message
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
Miscellaneous
Thread ID:
01337257
Message ID:
01337259
Views:
18
>I have cursor ptTemp and cursor tprinters
>Cursor ptTemp comes from aprinters ()
>The cursor tprinters is from a table
>
>In need to keep only records with have the same .name in both cursors
>
>The ADD method works, but the DELETE method does not work
>
>****ADD method
>**** if a record from ptTemp does not exist in tPrinters, add it to tPrinters
>
>SELECT ptTemp
> SCAN
>    SELECT tPrinters
>    LOCATE FOR ALLTRIM(UPPER(tPrinters.nome)) = ALLTRIM(UPPER(ptTemp.nome))
>     IF NOT FOUND ()
>
>     APPEND BLANK
>     replace tprinters.nome WITH ptTemp.nome
>              replace tprinters.porta WITH ptTemp.porta
>              replace tprinters.driver WITH ptTemp.driver
>
>              ENDIF
>              ENDSCAN
>
>
>*******************DELETE METHOD********************************************************
>   **** if a record from tPrinters does not exist in ptTemp, deletes it from ptTemp
>
> SELECT tPrinters
> SCAN
>    SELECT ptTemp
>    LOCATE FOR ALLTRIM(UPPER(ptTemp.nome)) = ALLTRIM(UPPER(tPrinters.nome))
>     IF NOT FOUND ()

       * You need to switch back to your original table
        
>        DELETE in tPrinters
>         ENDIF
>              ENDSCAN
>
>SET EXACT OFF
See correction inside.

But you can do it in just one DELETE-SQL command
DELETE tPrinters from tPrinters LEFT JOIN ptTemp T on 
UPPER(tPrinters.ptTemp.Nome) = UPPER(T.nome) where T.Nome is NULL
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform