Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Where is YAG? What are the reasons?
Message
From
03/04/2007 14:18:48
Walter Meester
HoogkarspelNetherlands
 
 
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01210085
Message ID:
01211742
Views:
16
>Smalll example: A client has multiple invoices. Determine the invoice that exceeded the cumulative balance of $1000. In VFP:
>
>Determine the invoice that winds up hitting the threshold....in what order?


Well let me help you.... There are a number of ways to do it, but one of them would be:
SELECT * FROM Invoices WHERE inv_pk IN 
    (SELECT inv_pk FROM 
        (SELECT a.inv_pk, a.inv_debt, SUM(b.Inv_debt) as previous 
             FROM invoices A 
                 LEFT JOIN invoices B ON A.inv_debno = B.inv_Debno AND A.inv_DateTime > b.inv_DateTime 
             WHERE inv_debno = ?nMyDebno 
             GROUP BY a.inv_pk, a.inv_debt
             HAVING SUM(b.Inv_debt) < ?nTreshhold ) AS a
        WHERE ISNULL(inv_debt, 0) + Previous > ?nTreshhold)
Now I did not test the above and it probably needs some tweaking before it works as intended. Now besides this solution is really much more difficult than the VFP version, it is performing unneccesary tasks as well, as it is accumulating a carthesian product and filtering it. It is VERY resource intensive.

These are the kind of problems that were not ment to be solved by SET ORIENTED approaches anyways, but still whole tribes of developers are doing this because the holy book promotes SET ORIENTED, sigh...
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform