Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Tricky sum
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire de rapports & Rapports
Titre:
Divers
Thread ID:
00220928
Message ID:
00220985
Vues:
20
>>>>>I can't figure out how to do this in report designer, or even if it's possible.
>>>>>
>>>>>Each of the line items in an invoice has a sales code attached to it. I need to take the first 5 sales codes and print them at the bottom along with the sum of the cost of the items with that sales code.
>>>>>
>>>>>Because of the screwy way SBT does reports, I need to do this in the report designer itself, rather than just doing a select into an array in the calling program like I had planned.
>>>>>
>>>>>I figured I'd have to use report variables somehow, but I don't know how. I won't know which codes will be summed, or their sums ahead of time. The records aren't and can't be grouped by sales code, so there may be an item of one sc, then one of another, then another of the first sc. I need to somehow pick out the first 5 sc's used, and add up the values, then print them at the bottom.
>>>>>
>>>>>Any ideas?
>>>>>
>>>>>Thanks,
>>>>>
>>>>>Michelle
>>>>Michelle,
>>>>As a quick idea, could you run an SQL for sums with top 5 into another cursor and use that in report too.
>>>>Cetin
>>>
>>>No, because the SQL would run on the whole table, and I need it only on certain records.
>>>
>>>I got a step closer. It looks like I can group by sales code after all. So I can probably get the totals. Not sure how to get the codes, though.
>>>
>>>Thanks,
>>>
>>>Michelle
>>
>>Michelle, I use UDFs in my reports similar to this.
>>* report is running and gets to the field
>>items_sum_for_salescode(itemcode) && this is the report field expression
>>
>>FUNCTION items_sum_for_salescode
>>LPARAMETER lcSalesCode
>>
>>LOCAL laSum[1]
>>store 0 to laSum[1]
>>SELECT SUM(itemcost) FROM INVOICE ;
>>WHERE invoice.salescode = lcSalesCode ;
>>INTO array laSum
>>
>>RETURN laSum[1]
>>ENDFUNC
>>
>>Here you need only to figure out how to run this only for 5 of your sales codes.
>>
>>HTH,
>>Nick
>
>P.S. I assume that the report cursor is different from invoice table, otherwise the SUM() function will move the record pointer in the selected area and mess up the report. I always use the report cursors.
>
>Nick

Unfortunately, it seems to use the table directly.

I hadn't thought of using a UDF. That helps. I printed out all your suggestions and I'll work from there.

Thanks to all of you,

Michelle
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform