Connecting to multiple databases on SQL Server

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
egolan
Posts: 1
Joined: Wed 22 Jun 2011 15:12

Connecting to multiple databases on SQL Server

Post by egolan » Wed 22 Jun 2011 15:30

I'm using Delphi 7 and SDAC to connect to Microsoft SQL Server.
When using MSQuery I like to retrieve data from multiple Databases. Does anybody know how to do that?

AndreyZ

Post by AndreyZ » Thu 23 Jun 2011 12:12

Hello,

You can use the following code:

Code: Select all

MSQuery.SQL.Clear;
MSQuery.SQL.Add('SELECT * FROM dbname1.dbo.tablename');
MSQuery.SQL.Add('UNION');
MSQuery.SQL.Add('SELECT * FROM dbname2.dbo.tablename');
MSQuery.Open;

Post Reply