SELECT bill_no, customer_name, SUM( detail_line.amount ) AS bill_total ; FROM bill_details JOIN bill_header ON bill_details.bill_no = bill_header.bill_no ; JOIN Customer ON bill_header.customer_no = Customer.Customer_no ; WHERE between( bill_header.bill_date, dStart, dEnd ) AND Customer.Customer.no = SomeValue ; GROUP BY bill_no, customer_name into cursor csrBill Totalswill give you all the bills for a specific customer in a particular date range. If you want all customers for that date range, modify the query like this:
SELECT bill_no, customer_name, SUM( detail_line.amount ) AS bill_total ; FROM bill_details JOIN bill_header ON bill_details.bill_no = bill_header.bill_no ; JOIN Customer ON bill_header.customer_no = Customer.Customer_no ; WHERE between( bill_header.bill_date, dStart, dEnd ) ; GROUP BY bill_no, customer_name into cursor csrBill Totals