Board index » delphi » Problem with ALIAS syntax in SQL query

Problem with ALIAS syntax in SQL query

Can anybody show me the correct syntax if I want to use more than one
alias in a SQL-query's FROM clause.

I tried this, but I keep getting the error "Table does not exists
table1".

Select *
from "alias1:table1","alias2.table2"
where table1.field1 = table2.field1

The database property of the SQL query was left blank because I am
specifying it in the SQL query.

Any suggestions will be welcomed.

Thank You

Tian Olivier

 

Re:Problem with ALIAS syntax in SQL query


Tian Olivier <olivi...@sabc.co.za> wrote in article
<32827B07.3...@sabc.co.za>...

Quote
> Can anybody show me the correct syntax if I want to use more than one
> alias in a SQL-query's FROM clause.

> I tried this, but I keep getting the error "Table does not exists
> table1".

> Select *
> from "alias1:table1","alias2.table2"
> where table1.field1 = table2.field1

Try ":alias1:table1"

HTH
Peter

Re:Problem with ALIAS syntax in SQL query


Quote
Tian Olivier wrote:

> Can anybody show me the correct syntax if I want to use more than one
> alias in a SQL-query's FROM clause.

> I tried this, but I keep getting the error "Table does not exists
> table1".
> The database property of the SQL query was left blank because I am
> specifying it in the SQL query.

Look up the Delphi help on heterogenous queries - it says, make a local
alias and specify that as the database for the query. This alias is then
used as temporary storage.

Re:Problem with ALIAS syntax in SQL query


Quote
Thomas Whitmore wrote:
> Tian Olivier wrote:

> > Can anybody show me the correct syntax if I want to use more than one
> > alias in a SQL-query's FROM clause.

> Look up the Delphi help on heterogenous queries - it says, make a local
> alias and specify that as the database for the query. This alias is then
> used as temporary storage.

The Delphi help on heterogenous queries isn't very helpful, as the
example doesn't show the necessary quotation marks.  

This example should help:

  SELECT TableA.Name, TableB.Salary, TableC.Department
    FROM ":Alias1:TableA.DBF" TableA,
         ":Alias2:TableB.DBF" TableB,
         ":Alias3:TableC.DBF" TableC
   WHERE TableA.MasterField = TableB.MasterField
     AND TableB.DetailField = TableC.DetailField

The real difficulty is in getting the parentheses right for the FROM
clause.  

--    
Beth Weiss
Strategic Analysis, Inc.
bwe...@wpgate1.wpafb.af.mil

Other Threads