Hi all.
I am trying to make a select work to load records into a popup form with only distinct values for what I’ve called ‘invoice_number’
My solution has an estimates table, a line_items table, an invoice_credit_join table, and an invoices table. Invoice credit join stores line item ids, and invoice ids, so that a history of all invoices and credits that an item has been on is saved, and we can look at an invoice containing line items from the past, even if those line items have been credited, and re-invoiced on another invoice.
My problem is in trying to get a popup window to show a list of invoices / credits that an estimate has had. It does work, but it shows multiple entries for each invoice number like this
8766
8766
8766
8766
8765
8765
8765
8765
When I want it to show only:
8766
8765
Seems simple enough…
So, my method which works but shows all numbers is:
var sql_query = "SELECT invoice_credit_join_id, invoice_id FROM invoice_credit_join WHERE sales_id = ?"
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(), sql_query , [forms.sale_master.salesid],-1)
forms.invoice_credit_history.controller.loadRecords(dataset)
application.showFormInDialog(forms.invoice_credit_history,-1,-1,-1,-1,'Invoice and credit history',false,false,false);
If I take out the invoice_credit_join_id, I get no foundset
If I add ‘DISTINCT’ after my select and ‘GROUP BY invoice_id’ after WHERE sales_id = ?, I get an error (SQL Anywhere Error -149: Function or column reference to ‘invoice_credit_join_id’ must also appear in a GROUP BY).
If I add invoice_credit_join_id to the GROUP BY, it just goes back to the original problem and shows multiples of each invoice / credit number.
What I want is to select every invoice_credit_join id where invoice_id is distinct from a table whose pk is invoice_credit_join_id and load the results (invoice_id) into a popup window.
I’d be grateful for any help…
Thanks
Bevil