Re: Using TADOQuery for select using two tables



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-------


.



Relevant Pages

  • Re: Outgoing POP3 email missing/lost/not received
    ... Funny thing is that I have had this ISP for 8 years and it has always been ... It looks like when you last ran CEICW, you set the ISP's mail server to: ... Internet Connection Wizard. ... After the wizard completes, the following network connection ...
    (microsoft.public.windows.server.sbs)
  • Re: Cannot connect client to server 2003
    ... you need to reconfigure the IP schema of your SBS ... On the SBS 2003 Server open the Server Management console. ... On the Connection Type page, click Broadband, and then click Next. ... Alternate DNS server, type the IP addresses that are provided by your ISP ...
    (microsoft.public.windows.server.sbs)
  • Re: Outgoing POP3 email missing/lost/not received
    ... ISP's mail server instead of the domain name on the ... SUMMARY OF SETTINGS FOR CONFIGURE E-MAIL AND INTERNET ... Internet Connection Wizard. ... After the wizard completes, the following network connection ...
    (microsoft.public.windows.server.sbs)
  • Re: Networking Question - VLANs on SBS 2003 Premium SP1
    ... port on the old router so I now have a segregated WLAN. ... be sure you do not enable any DHCP server in internal network. ... On the Connection Type page, click Broadband, and then click Next. ... On the Network Connection, You must enable and configure the network ...
    (microsoft.public.windows.server.sbs)
  • Re: Urgent! New router and big disaster
    ... In the DHCP Console... ... Right click the DHCP server icon, ... Server Local Area Connection: ... Les Connor [SBS Community Member - SBS MVP] ...
    (microsoft.public.windows.server.sbs)