Subject RE: [firebird-support] best way of selecting some records of a table
Author Sasha Matijasic
> Hello, I want to implement a very normal task... Lets say the user is
> generating
> report with some customers' movements and he/she select some of them to
> print.
> In the past I did it, with a field "selected" in customer table. But I
> know that
> this is a very bad practice in a multiuser enviroment. I have FB2.1 and
> I know I
> have temp tables now and I could create a table and store the selected
> IDs in
> there. I've never did it before, and don't know how to do it. I use
> IBX/Delphi
> 6. I have no component to create a temp table. How can I create it?
> Should I
> delete the table after using it? Is there some example in the net about
> how to
> work with Temp Tables in FB ? Is that aproach, the best way to selec
> some
> records of a table? Thanks!! -sergio
>
Hi,
You create temp tables like this:

create global temporary table table_name(...)
on [ON COMMIT <DELETE | PRESERVE> ROWS];

Note that, the structure of the table is not temporary, only the data you insert is during the transaction (on commit delete rows) or connection (on commit preserve rows). Therefor, you create them the same way you create your other persistent tables.

There was a similiar question a couple of months ago and I described how to work (with classis tables, not GTTs) with such setup for reporting, you can read about it here:
http://tech.groups.yahoo.com/group/firebird-support/message/95322
Read it and feel free to ask for details if it's not clear enough.

You don't dynamically create or delete the table, and the data is deleted when transaction ends (or connection, whichever you need, although if you do reporting, transaction is prefered).

I don't know if what you are trying to do is the best way, but I would do it exactly like that :)

Sasha