>>>Hi:
>>>
>>>The following SQL produces the following output. Obviously there's something wrong with the IIF, but how do I guard against division by zero?
>>>
>>>Thanks,
>>>
>>>Yossi
>>>
>>>SELECT SUM(FeedWeight) FeedWeight, ;
>>> SUM(FeedCost) FeedCost, ;
>>> IIF(SUM(FeedWeight) = 0,0,SUM(Feedcost)/SUM(FeedWeight)) FeedCostPerlbFeed ;
>>> FROM prereportcursor ;
>>> INNER JOIN curCoop ;
>>> ON curCoop.CODE = feedmill ;
>>> GROUP BY curCoop.CODE ;
>>> INTO CURSOR ReportCursor
>>>
>>>
>>>FEEDWEIGHT FEEDCOST FEEDCOSTPERLBFEED
>>> 0.00 0.00000000 0
>>> 3270490.00 245.77180000 0
>>> 4286240.00 398193.47120000 0
>>>
>>
>>Yossi - I can't remember whether you're using VFP 9. If so, the way to go is with a derived table:
>>
>>>
>>SELECT FeedWeightTotal, ;
>> FeedCostTotal, ;
>> IIF(FeedWeightTotal = 0,0,FeedcostTotal/FeedWeightTotal) FeedCostPerlbFeed ;
>> FROM ;
>> (SELECT SUM(FeedWeight) AS FeedWeightTotal, ;
>> SUM(FeedCost) AS FeedCostTotal ;
>> FROM prereportcursor ;
>> INNER JOIN curCoop ;
>> ON curCoop.CODE = feedmill ;
>> GROUP BY curCoop.CODE) Totals ;
>> INTO CURSOR ReportCursor
>>
>>
>>
>>Tamar
>
>Hi Tamar:
>
>1. Why is your approach better than Suhas Hegde's?
>2. When I first created the thread, I was asked to specify my VFP version. Is that accessible to you and if not what is the point of supplying that information?
>
>Thanks,
>
>Yossi
Hi Yossi,
1. Tamar's version will only work for VFP9. I haven't checked difference with Suhas's version
2. It looks like there is some bug in UT interface that manifests in some cases. Try to create a new thread in Chatter/UT related problems section.
If it's not broken, fix it until it is.
My Blog