Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

running query on existing tquery arghhhh

Status
Not open for further replies.

GlynW

Programmer
Feb 14, 2001
22
0
0
GB
I'm having (i think) a syntax Referencing problem when trying to run a query on 1 table and 1 existing tquery.

The problem is I want to run the tquery linking an ordinary mytable.db to a query I've already created using a TQuery.

Example:

//**** THE FIRST QUERY ******
strSQL := TStringList.Create;
with strSQL do
begin
Add('select *');
Add(Format('FROM "%s",[DataPath+'MYTABLE1.DB']));
end;
tquery1.SQL.Clear;
tquery1.SQL.Assign(strSQL);
tquery1.Open;

//**** THE SECOND QUERY ******
strSQL := TStringList.Create;
with strSQL do
begin
Add('Select <LIST OF FIELDS ETC>)');
Add(Format('FROM &quot;%s&quot;,&quot;%s&quot;',[DataPath+'MYTABLE2.DB','tquery1']));
Add('WHERE <CONDITION THAT MATCHES THEM>');

The first query does some formatting, so i am able to link the two together.

The problem I am having is that the second query finds MYTABLE2.DB no problem, but cannot find tquery1, it says table not found, which I know it wont find because it's in memory and not a physical table.

So my question is how can i reference the tquery inside an sql FROM statement.

Any help would be great.

Thanks
Glyn
 
hi

Don't think you can do it the way you want. You may simply need a Join or Union in the original query and therefore get the result set you want from one SQL statement.

If you give us more info on the tables and what you want to extract from them, we can look at writing the SQL for you.

lou

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top