Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Deleting records from 2 tables vfp

Posted on 2013-05-23
5
Medium Priority
?
519 Views
Last Modified: 2013-05-23
Hi:
I am running a capacity planning database. This copies all relevant records from oracle and stores them in a table called capacity. The copy routine is run several times a day, and the capacity is seen to rise as orders are added to oracle. I can report that at say 8am there were 5000 orders and at 5pm there were 5500 but have been challenged to provide details.
My solution is to create a copy of the capacity table (called lastcap) before the update, and again after (called thiscap). What I need to do is 'remove'  those records that are in both tables (or read only those that are in the later table). Does anybody know the best way of achieving this?
Thanks!
0
Comment
Question by:ClaytonGlass
[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
5 Comments
 
LVL 43

Accepted Solution

by:
pcelba earned 1000 total points
ID: 39191063
Each table record should have its own unique ID, e.g OrderID. This is the only requirement for the following query:

SELECT * FROM Capacity
WHERE OrderID NOT IN (SELECT OrderID FROM LastCap)

5000 orders isn't so many so it will be fast even without indexes.
0
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 39191065
SELECT * FROM table1 WHERE id NOT IN (SELECT id FROM table2)
0
 
LVL 43

Expert Comment

by:pcelba
ID: 39191077
If you don't have unique ID then you have to use some time stamp but you have to ensure timestamp values can do the job, e.g. two orders having same time stamp but just one of them exported the first time will produce incorrect result.

SELECT * FROM Capacity
WHERE TimeStamp > (SELECT MAX(TimeStamp) FROM LastCap)
0
 

Author Closing Comment

by:ClaytonGlass
ID: 39191095
Thanks a lot for very prompt and effective answers! I asked a question about python 2 months ago and am still waiting! Thanks to Captain Cyril, too.
0
 
LVL 30

Expert Comment

by:Olaf Doschke
ID: 39192322
What makes me think is, you say you compare lastcap and thiscap, two copies of the capcity table before and after update.

But there is an update routine (in oracle?) which does merge oracle data into capacity.dbf, so at that stage it's already known, which records already were in capacity.dbf and which have to be added.

So I'd say the solution to your problem is already solved and you redo this by the comparison. Even if it's not much to do, when this raises at 500 records per 3 hours, you sooner or later will see a slow down, just even making the copies before and after merges will take longer and longer.

What I would question is, if the only difference is added records, because then you'd only need to store the reccount before and after the data merging, and will know how many records are new in the DBF. And as new records always are appended at the end of a dbf file, you'd then know the new records are from oldreccount+1 to EOF.

And that doesn't need two DBFs to compare.

Bye, Olaf.

PS: If this wasn't oracle, but T-SQL and the merging would be done inside SQL Server, I'd have an idea to both merge data and output the records that changed or were added as new orders with the OUTPUT clause of a MERGE Statement (an SQL command VFP does not have, though, and I don't know about oracle).

And there are even better options about logging changes via triggers and then export that changelog table. Transaction log also is one source of such change data, even without any triggers. Again I only know for SQL Server you can make use of DBCC LOG.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
In this article, WatchGuard's Director of Security Strategy and Research Teri Radichel, takes a look at insider threats, the risk they can pose to your organization, and the best ways to defend against them.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

721 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