Board index » delphi » Can I Query the result set of a TQuery component???????????

Can I Query the result set of a TQuery component???????????

I have a TQuery Control that pulls data from several tables. Is there a way I
can query the results of Query1 as a seperate dataset or maybe select the
results of Q1 to a new table (Paradox)

IE     Select A, B, C into NewTable from SourceTable

I can not figure out how to do this using Delphi and Paradox but this is very
simple with VB and Access.

Any direction is appreciated

Steve

 

Re:Can I Query the result set of a TQuery component???????????


Why would you want to do this? A TQuery is a TDataSet (ie it inherits
from it) and you can use all methods and properties of TDataSet on it.
If you really need to create a new table, I should think you could do
that directly with SQL, using a sub-query.

hth
Gerhard

Quote
SR3365 wrote:

> I have a TQuery Control that pulls data from several tables. Is there a way I
> can query the results of Query1 as a seperate dataset or maybe select the
> results of Q1 to a new table (Paradox)

> IE     Select A, B, C into NewTable from SourceTable

> I can not figure out how to do this using Delphi and Paradox but this is very
> simple with VB and Access.

> Any direction is appreciated

> Steve

--
---------------------------------------------------------------------
Dr. Gerhard Grosse       Phone:   +49 89 289-12567
Physik-Department E15    Fax:     +49 89 3206780
TU Muenchen              E-mail:  ggro...@ph.tum.de
D-85747 Garching         http://srv.e15.physik.tu-muenchen.de/grosse/
Germany
---------------------------------------------------------------------

Re:Can I Query the result set of a TQuery component???????????


Unfortunately, this isn't as easy in Delphi as it should be.  There are
two (probably others as well) ways that I can think of.  

1.  Copy the results of the query to a temporary table and run the query
on it.  This can be done fairly easily using dbiMakePermanent.  

2.  Use a subquery in the original SQL.  You can often formulate a
subquery that will do the job even if it complicates the syntax.

Ed

SR3365 <sr3...@aol.com> wrote in <19990520125504.08836.00004448@ng
-ch1.aol.com>:

Quote
>I have a TQuery Control that pulls data from several tables. Is there a
>way I can query the results of Query1 as a seperate dataset or maybe
>select the results of Q1 to a new table (Paradox)

--
Ed Hochman - MBH Systems

Re:Can I Query the result set of a TQuery component???????????


Had a friend looking for this one recently. . . He dug for days and was told
that he could not query the results of a query without writing a temporary file.

There is, however, a work-around.

For your first query, use the DataBase Desktop's New Query. Save it as a .QBE
file.
In Delphi Help, look up SELECT (in all caps) and read the last line:

SELECT * from "filename.qbe".

Delphi will recognise the QBE (which contains an imbeded private directory
reference which you can set), run the first query to a temporary table, run the
code's second query against that temporary table, and clean up after itself.
You can even Request Live on the set...

Hope it gets you where you're going...

Al

Quote
SR3365 wrote:
> I have a TQuery Control that pulls data from several tables. Is there a way I
> can query the results of Query1 as a seperate dataset or maybe select the
> results of Q1 to a new table (Paradox)

> IE     Select A, B, C into NewTable from SourceTable

> I can not figure out how to do this using Delphi and Paradox but this is very
> simple with VB and Access.

> Any direction is appreciated

> Steve

Re:Can I Query the result set of a TQuery component???????????


Check out the Filter property
Good luck.
Gene

Quote
SR3365 wrote in message <19990520125504.08836.00004...@ng-ch1.aol.com>...
>I have a TQuery Control that pulls data from several tables. Is there a way
I
>can query the results of Query1 as a seperate dataset or maybe select the
>results of Q1 to a new table (Paradox)

>IE     Select A, B, C into NewTable from SourceTable

>I can not figure out how to do this using Delphi and Paradox but this is
very
>simple with VB and Access.

>Any direction is appreciated

>Steve

Re:Can I Query the result set of a TQuery component???????????


On Fri, 21 May 1999 15:24:20 -0500, Al White

Quote
<SpamTrollDivers...@notmail.com> wrote:
>Had a friend looking for this one recently. . . He dug for days and was told
>that he could not query the results of a query without writing a temporary file.

>There is, however, a work-around.

>For your first query, use the DataBase Desktop's New Query. Save it as a .QBE
>file.
>In Delphi Help, look up SELECT (in all caps) and read the last line:

>SELECT * from "filename.qbe".

>Delphi will recognise the QBE (which contains an imbeded private directory
>reference which you can set), run the first query to a temporary table, run the
>code's second query against that temporary table, and clean up after itself.
>You can even Request Live on the set...

Or, on later versions of the BDE, the initial SQL statement can be saved to
a .SQL file and queried. Local SQL can use either a Paradox QBE query saved
to file or an SQL statement saved to file. This saves on trying to convert
the initial SQL statement to Paradox QBE to save it to a file. Instead, the
SaveToFile method of string list classes (of which the TQuery.SQL property
is one) can be used.

  Query1.SQL.SaveToFile('FileName.sql');
  with Query2 do begin
    Close;
    SQL.Clear;
    SQL.Add('SELECT *');
    SQL.Add('FROM "FileName.sql"');
    Open;
  end;

A WHERE clause can be added to the query against the saved SQL file to
further limit the rows used.

The result set represented by a saved SQL query can be joined to a base
table or to another SQL file.

//////////////////////////////////////////////////////////////////////////
Steve Koterski                   "There are two kinds of pedestrians...the
Technical Publications           quick and the dead."
INPRISE Corporation                            -- Lord Thomas Robert Dewar
http://www.borland.com/delphi                                  (1864-1930)

Other Threads