RandyBosma
Thu Sep 06 12:42:05 PDT 2007
Bev-
You've given us a small fragement of what I'm guessing is a larger block of
code that probably sums order detail lines to figure out the order total
amount and then (guessing) puts that number in a field of the ordent table.
SELECT ordent && parent
onum = ordernum
SELECT ordernum, SUM(qtyord*price) AS otot ;
FROM orddet ;
GROUP BY ordernum ;
HAVING ordernum = onum ;
INTO CURSOR oTotal
USE IN orddet && closes order detail table
SELECT ordent
GOTO RECNO()
* and do more.......
Theoretically you'll have one record. The field oTotal.otot will contain the
number I think you're interested in. (This code should also work in fox2x.)
If you describe in more detail what you're trying to accomplish, perhaps
someone can suggest another method of accomplishing your objective. The
SELECT - SQL statement is powerful and generally faster (given appropriate
indexes) than SCANs and SEEKs.
Should you need to prove that the speed is or is not an issue, you can wrap
each code fragment with statements to capture the SECONDS() before and after,
and calculate the elapsed time.
HTH,
Randy Bosma
Beverly Howard [Ms-MVP/MobileDev] wrote:
>I need to collect and sum data from related database, something I know
>how to do in fox2x based on the speed and efficiency limits of that
>platform, but would like to get input on (efficient) ways to do the same
>in vfp.
>
>Assuming a large related table with a handful of records meeting the
>relation scope, how would I best sum a (non indexed) numeric field field
>for the scope of the relation?
>
>here's what I assume would still be most efficient;
>
>select ordent &&parent
>onum = ordernum
>select orddet &&o2m child
>if seek(onum)
> CALCULATE sum(qtyord * price) while ordernum = onum TO otot
> *or
> sum (qtyord * price) TO otot while ordernum = onum
>endif
>select ordent
>goto recno()
>
>Thanks in advance,
>Beverly Howard
--
Message posted via DBMonster.com
http://www.dbmonster.com/Uwe/Forums.aspx/foxpro-general/200709/1