Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL to purge old orders and customers
Message
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01162715
Message ID:
01162720
Views:
16
>I have a cust.dbf and an orders.dbf. I want to create some SQL to purge older records. If the customer has not ordered anything in the last two years, I want to delete all his orders and his customer record. There is a unique CUST_KEY field in cust.dbf and orders.dbf. orders.dbf also has SEQ and ADD_DT fields.
>
>Thanks
>
>Brenda
select custID, OrderID from Orders ;
inner join (select custID, max(Order_Date) as LastOrderDate ;
from Orders group by 1 ;
having LastOrderDate < date() - 365*2) LastOrder ;
on Orders.CustID = LastOrder.CustID into cursor OrdersToDelete
Proceed from there.

Not tested.
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