Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Tai Nguyen
  Where is Tai Nguyen?
 
 United States
 Tai Nguyen
 To: Ammar Hadi
  Where is Ammar Hadi?
 Al-Samawah
 Iraq
 Ammar Hadi
 Tags
Subject: RE: code to mark for delete
Thread ID: 228441 Message ID: 228519 # Views: 1 # Ratings: 0
Version: Visual FoxPro 9 Category: Databases, Tables and SQL Server
Date: Tuesday, May 19, 2009 3:30:02 PM         
   


> > I wrote a program to do this before and I can't find that program again. Basically, I will have 2 tables called Table 1 and Table2.
> >
> > USE "c:\Table1.dbf" AGAIN IN 0 SHARED
> > USE "C:\Table2.dbf" AGAIN IN 0 SHARED
> >
> > Select training
> >
> > Goto top
> >
> > SCAN FOR DELETED()
> >
> >
> > DELETE FROM Table2 WHERE RECNO("Table2") = RECNO("Table1")
> >
> >
> > ENDSCAN
> >
> >
> >
> > Table1 and Table2 are the same structure and data. The code will read what record numbers have been deleted in Table1 and mark delete for the same records in Table2.
> >
> > Thanks,
> >
> > Tai Nguyen.
>
> Hi Tai,
>
> I prefer you depend on an id field in the WHERE clause rather than the recno() so that you will not care in which order the tables are ordered.
>
> So,
>
> LOCAL lcSet
> lcSet=SET("DELETED")
> 
> SET DELETED OFF
> 
> DELETE  table2 FROM table1;
>  WHERE table1.myID = table2.myID;
>  AND DELETED("table1")
> 
> SET DELETED &lcSet
> 

>
> If you want to use SCAN .. ENDSCAN
>
> LOCAL lcSet
> lcSet=SET("DELETED")
> 
> SET DELETED OFF
> 
> SELECT Table1
> SCAN FOR DELETED("Table1")
>  DELETE FOR table2.myID=table1.myID IN table2
> ENDSCAN
> 
> SET DELETED &lcSet
> 

>
> But there are some notes on your request:
> 1)What is the rule of the cursor (training)?
> 2) In your scenario you are opening the same table twice, so it will be identical unless you have code before the delete command that manipulates table1 and delete some of its records.
>
> Hope this helps
>
> Ammar Hadi ................IRAQ
>
> My Foxite Weblog
>
> ---------------
> I I I really love foxite
> ___________________________


Good morning from American Ammar, hahaha. How are you doing? I love foxite too. People contributed quite a lot to me in this forum. The way my tables designed without myID as some unique ids and so when I ran your code, it deleted all the records in the table. Here is the code I made it to work with my tables (your code refreshed my memory a little bit and I think your code would work with that design too.) Thanks for the help. By the way, yes the tables are identical (sorry, training is table1).

This code worked:

SET DELETED OFF

SELECT Table1
SCAN FOR DELETED("Table1")
DELETE record RECNO("Table1")IN Table2
ENDSCAN

Tai Nguyen.

ENTIRE THREAD

code to mark for delete Posted by Tai Nguyen @ 5/18/2009 11:48:01 PM
RE: code to mark for delete Posted by Ammar Hadi @ 5/19/2009 12:51:30 AM
RE: code to mark for delete Posted by Tai Nguyen @ 5/19/2009 3:30:02 PM
RE: code to mark for delete Posted by Ammar Hadi @ 5/19/2009 3:44:52 PM
RE: code to mark for delete Posted by Tai Nguyen @ 5/19/2009 7:26:48 PM
RE: code to mark for delete Posted by Ammar Hadi @ 5/20/2009 10:57:07 AM
RE: code to mark for delete Posted by Tai Nguyen @ 5/20/2009 5:02:37 PM
RE: code to mark for delete Posted by M. Akram Bhatti @ 5/19/2009 6:54:22 AM
RE: code to mark for delete Posted by Tai Nguyen @ 5/19/2009 3:34:09 PM
RE: code to mark for delete Posted by Ravi Taxali @ 5/21/2009 4:00:27 PM