Re: ON FIRST ROW
Posted in 1995
> > We use the following technique to create the equivalent of a ON FIRST ROW > clause. It is extremely useful when you want to declare cursors in > a report only once, or perhaps do some sub-totalling on all rows sent > down to a report when group sum() won't work. > > foreach c_report into p_vars.* > output to report rpt(1,p_vars.*) > end foreach > > The report then looks as follows : > > report rpt(r_first_row, r_vars) > > define r_first_row smallint > define r_vars record like vars.* > > order external by r_first_row, r_vars.other_group > > before group of r_first_row > declare cursors... > initialize r_sub_totals > > Comments please... Yuk! Always try to get your database activity out of the way outside of the report function, because: (1) Joined queries are nearly always faster than nested cursors, unless you've got the indexes wrong (for all the usual reasons that I can't be bothered to list...) (2) It makes your code neater and easier to follow. It's also the way SQL-based products were intended to work. (3) If you can get the grouping out of the way before invoking the OUTPUT TO REPORT you save the report formatting function having to generate temp tables. SQL could possibly have evaluated the grouping through an index, or at least sort-merge joins, which are faster. akent@cix.compulink.co.uk (Andy Kent) -------------------------------------