Board index » delphi » Query across multiple DB Servers

Query across multiple DB Servers

Hey all -

I would like to perform a query that selects data from 2 seperate databases.
How do I set up my TQuery to do this and what would my SQL Text look like?

Thanx in advance!

Bob

 

Re:Query across multiple DB Servers


Use Heterogeneous query.

This is a fragment from the on-line help that can help you.

To perform a heterogeneous query, follow these steps:

1 Define separate BDE aliases for each database accessed in the query. Leave
the DatabaseName property of the TQuery blank; the names of the two
databases used will be specified in the SQL statement.
2 Specify the SQL statement to execute in the SQL property. Precede each
table name in the SQL statement with the BDE alias for the database where
that table can be found. The table reference is preceded by the name of the
BDE alias, enclosed in colons. This whole reference is then enclosed in
quotation marks.

3 Set any parameters for the query in the Params property.
4 Call Prepare to prepare the query for execution prior to executing it for
the first time.
5 Call Open or ExecSQL depending on the type of query to execute.

For example, suppose you define an alias called Oracle1 for an Oracle
database that has a CUSTOMER table, and Sybase1 for a Sybase database that
has an ORDERS table. A simple query against these two tables would be:

SELECT Customer.CustNo, Orders.OrderNo

FROM ":Oracle1:CUSTOMER"
  JOIN ":Sybase1:ORDERS"
    ON (Customer.CustNo = Orders.CustNo)
WHERE (Customer.CustNo = 1503)

You can find more info in the subjets "Developing DataBase applications" on
the delphi on-line help.

Harold L. Marzan
R&D iSaturno.
hmarzan_merc...@hotmail.com

Quote
Bob Goldstine <ttgchic...@aol.com> wrote in message news:398eea1b_2@dnews...
> Hey all -

> I would like to perform a query that selects data from 2 seperate
databases.
> How do I set up my TQuery to do this and what would my SQL Text look like?

> Thanx in advance!

> Bob

Other Threads