I would like to delete records based on a date field range where the date
field is in table one and also delete the related records in table two, the
tables are related by a string field called "reference" in table one and
"Call Reference" in table two.
Could someone give me an sql example please.
--
Guillermo Castaño A.
www.GrupoMillennium.com
"Atool Vegad" <Atool...@irpc.co.uk> wrote in message
news:3ec0fadd$1...@newsgroups.borland.com...
To Atool:
You might have to use BeforeDelete Event of the master query in Delphi.
procedure Tform1.ADOQuery1BeforeDelete(DataSet: TDataSet);
var
sql:string;
n:integer; //number of affected records
begin
//assuming that reference is string. (if it is a number us %d instead of %s)
sql:=format('DELETE * FROM tbl2 WHERE ref=%s ;',[dataset.fieldbyname('ref').asString])
AdoConnection1.execute( sql,n);
end;
I have not tried the code myself but logically it should work.
Good Luck.
Emmanuel
procedure Tform1ADOTable1BeforeDelete(dataset:TDataset);
var
q:tadoquery;
begin
//I have assumed AdoTable1 is the master table
q:=tadoquery.create(nil);
q.connection:=TADOTable1.connection;
q.sql.add(format('DELETE * FROM tblDetail WHERE ref=%s ;', [dataset.fieldbyname('ref').asString]);
q.execSql;
q.free;
end;
You will like to put the code in try...except block to catch exception.
Best regards
Emmanuel
Access does not support doing this in a single query.
Something like this is what you want to use for deleting records in the related
table. Once you have done that you can run another query to delete from the
primary table.
Delete Table1
from table1D join table2 D2 on D.someField = D2.somefield
where DateField = :DateParam
--
Brian Bushay (TeamB)
Bbu...@NMPLS.com
----------------------------------------------------------------
Regards,
Viatcheslav V. Vassiliev
http://www.oledbdirect.com
The fastest way to access MS SQL Server, MS Jet (MS Access)
and Interbase (through OLEDB) databases.
"Atool Vegad" <Atool...@irpc.co.uk> сообщил/сообщила в новостях
следующее: news:3ec0fadd$1...@newsgroups.borland.com...
Nothing to do ;)
I missread the question