Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Where is YAG? What are the reasons?
Message
De
03/04/2007 14:18:48
Walter Meester
HoogkarspelPays-Bas
 
 
À
03/04/2007 13:03:49
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Database:
Visual FoxPro
Divers
Thread ID:
01210085
Message ID:
01211742
Vues:
15
>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...
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform