Re: Using TADOQuery for select using two tables
- From: yannis <none@xxxxxxxxxx>
- Date: Tue, 19 Feb 2008 12:43:18 +0200
Jauch formulated on Παρασκευή :
Hi!
I need to put some data that are on a table on server 1 to other table on server 2.
Some data may be alread on the server 2, and because I want to let the user chose, from the data on server 1 that is not yet on the server 2, I think of use something like this:
On ADOQuery1 (Connection to server 1, DataSource -> DataSource1)
SELECT a, b
FROM table1
WHERE (v = 0)
AND
(a <> :a2)
On ADOQuery2 (Connection to server 2)
SELECT * FROM table2
On DataSource1 DataSet -> ADOQuery2
The problem is that way, The only record that is alread on server 2 that do not appear on my select is the first, the others continue to appear.
How can I make may select return ONLY the records in table1 that are not in table2?
Thanks for any help!
--- posted by geoForum on http://delphi.newswhat.com
WEll there a number of ways to accomplish depending on the SQL server you are using for example in MSSQL server you can have cross DB queries and linked servers that you can use any database on any server through a single connection and you are not required to have two Connection objects on your form. A more general way, which shoold work on all servers, is to have two connections two adoQueries as you have allready demonstrated and use the OnFilterRecord event to filter out records from the primary ADOQuery that can be located on the secondary ADOQuery.
eg.
procedure TForm1.ADOQuery1FilterRecord(DataSet: TDataSet; var Accept: Boolean);
begin
Accept := not (adoquery2.Locate('KeyField',AdoQuery1.FieldByName('KeyField').Value,[loCaseInsensitive]));
end;
Regards
Yannis.
--
You talk a great deal about building a better world for your children, but when you are young you can no more envision a world inherited by your children than you can conceive of dying. The society you mold, you mold for yourself.
----Russell Baker-------
.
- Prev by Date: Re: Cant trap Exception.
- Next by Date: Re: Cant trap Exception.
- Previous by thread: Re: Using TADOQuery for select using two tables
- Next by thread: Cant trap Exception.
- Index(es):
Relevant Pages
|