> Select Dates,pty_codes,Sum(Amt) group by dates,pty_code from my_table where pty_code=m.my_pty_code and betw(dates,m.start_dates,m.end_dates) into cursor tmp_cursor
*This part takes about as much time as SQL does.
set filt to betw(dates,m.start_date,m.end_date) and pty_code=m.mty_code
*This part is now summing and producing the output which SQL does internally and much faster.
set order to tag ixdates
store dates to xdates
sum while dates=m.Xdates to lnSum
insert into tmp_cursor (dates, pty_code, sum) values (m.xdates, m.pty_code, m.lnSum)