Re: SQL query
Posted in 1998
I wrote:
> I've written a 4GL program to produce a report and the SELECT
> statement looks like this:
> SELECT sotrn.repnum, stmst.grplup, sotrn.accnum,
> SUM(sotrn.totalord), SUM(sotrn.totalord*sotrn.price)
> FROM sotrn, stmst
> WHERE sotrn.co_id = g_conum
> AND sotrn.orderid >= p_orderid
> AND sotrn.repnum BETWEEN p_startrep AND p_endrep
> AND sotrn.stat_ind != p_cancode
> AND sotrn.ordertype = "F"
> AND sotrn.crt_date <= p_crt_date
> AND stmst.co_id = g_conum
> AND stmst.productid = sotrn.productid
> AND stmst.season MATCHES p_season
> AND stmst.grplup MATCHES p_productgrp
> GROUP BY sotrn.repnum, sotrn.accnum, sotrn.stmst.grplup
> ORDER BY sotrn.repnum, sotrn.accnum, sotrn.stmst.grplup
Just get rid of the SQL SUMs and GROUP BY and do ALL of the totaling in
the report module using ITS SUM function and global variables. You are
thinking too hard! K.I.S.S.
Art S. Kagel