Board index » delphi » Query from query

Query from query

I have big enough query with UNIONs and agregatives.
And then I need to build query that use result of first one.
But I can't use VIEW because UNIONs are illegal in VIEWs.
I can't build one big query because UNIONs haven't
a name and impossible to apply to fields names for joins.

In Access it is possible create first
query and save it like QUERY1 and then
write next query (simplified example):

SELECT Q1.f1, T1.* FROM QUERY1 Q1, Table1 T1
WHERE Q1.id = T1.id

(But Delphi don't allow to query from query ;-( )

In DB2 it is possible to write:

SELECT Q1.f1, T1.* FROM (SELECT ...) Q1, Table1 T1
WHERE Q1.id = T1.id

(But IB don't allow to query from query ;-( )

Who know how to query from query on Delphi and
Interbase ?

 

Re:Query from query


Hi,

No, Delphi don't, do it? But you can try to save the results of the query to
a local table, by doing this:

uses BDE;

procedure SaveQueryToTable(qryQ: TQuery; stableName: String);
var
pTableName: Array[0..255] of Char;
begin
    StrPCopy(pTableName, stableName);
    Check(dbiMakePermanent(qryQ.Handle, pTableName, True));

Hope this helps, then you query from the table stableName.

Alternatively, if I'm missing the point about your database being Interbase,
can you not save the query to an Interbase table using SQL and query from
that?

Regards,
Paul Harding.

Quote
Andy Neverowsky wrote in message ...
>(But Delphi don't allow to query from query ;-( )

Re:Query from query


On Mon, 17 Jan 2000 21:17:27 -0000, "Paul Harding"
Quote
<p...@paulharding.fsnet.co.uk> wrote:

>No, Delphi don't, do it? But you can try to save the results of the query to
>a local table, by doing this:

>uses BDE;

>procedure SaveQueryToTable(qryQ: TQuery; stableName: String);
>var
>pTableName: Array[0..255] of Char;
>begin
>    StrPCopy(pTableName, stableName);
>    Check(dbiMakePermanent(qryQ.Handle, pTableName, True));

>Hope this helps, then you query from the table stableName.

I hope too. I will try that.

Quote
>Alternatively, if I'm missing the point about your database being Interbase,
>can you not save the query to an Interbase table using SQL and query from
>that?

I can. But I'm not sure that it will be fast enough.
And I will need to grand all users that work with
this database rights to create tables.
Say if 20 users are connected to database
they  must create 20 different tables for
each query. If some of this users loose
connections who will drop this tables ?

This way are possible but not so simple
like we want

Other Threads