Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Different behavior of COUNT(*) and SUM()
Message
De
04/11/2008 21:28:53
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Vista
Network:
Windows 2008 Server
Database:
MS SQL Server
Divers
Thread ID:
01359217
Message ID:
01359682
Vues:
39
>>Hi,
>>
>>If I select records that don't satisfy my criteria I get 0 for count(*), but NULL for sum(IIF(myCondition, 1,0))
>>
>>Is this a documented beahvior?
>>
>>Thanks.
>
>Hi William,
>
>I don't think this behavior is properly documented in Help. All I can find is
>-------------------------------------------------------------------------------------------------------------
>When you use aggregate functions, such as MAX( ), in the SQL SELECT command without a GROUP BY clause, and the system does not find any matching records, Visual FoxPro returns a result set with a single record and it sets _TALLY to 1. In versions before Visual FoxPro 9.0, the system does not return any records and it sets _TALLY to 0.
>--------------------------------------------------------------------------------------------
>
>It doesn't tell you that COUNT may return a number and the SUM would return NULL. So, I guess, you can find this by trial and error method.

Basically, yes. But it makes sense - count(*) will return the count of _any_ records, therefore no nulls because it is counting real records, and "no records found" returns a real zero, not a null, because it can't say "I don't know whether I found any records".

SUM(), however, has to account for the case when all the fields it sums contain null - in which case, the total will be equally absent, i.e. sum of no-not-null numbers is a null (how's "no-not-null" for a triple negation, eh?).

OK, one more try: if sum(xField) is sum of all nulls, what else can it be but null? Can't invent numbers when there aren't any.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform