Subject selecting some records from table
Author shg_sistemas
Hello, I need to do a simple Selling by Customers report, but the user has to be able to select some of the customers or all of them.

So I have a temp table (on commit delete rows) with a field "ID" and I just copy the IDs of the selected customers to it.

Then I construct my select like this:

select * from invoices
where
(
:All_Customers = -1
)
or
(
exists
(select ID
from selected_customers
where invoices.id_customer = selected_customers.id)
)

So, if I want all the customers I just set All_Customers = -1

The question is: is that the correct (and *BEST/FASTEST*) way to do it??

Just in case, I use FB2.1

Thanks!

Sergio