Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 2 of 2 total
Thread deleting records depending on other table data
Wed, Mar 8 2006 6:23 AMPermanent Link

"Harry de Boer"
LS

table A (Aid)
table B (Bid, Aid, begindate, enddate)
table C (Cid, date)

If I delete a record from table A the records in table B where B.Aid=A.Aid
must also be deleted. No problem. But how do I delete the records in table C
where C.date BETWEEN  B.begindate AND enddate, but only of course for the
record(s) where B.Aid=A.Aid

Can this be done in one statement?

Regards, Harry

dbIsam 3.30, D6

Wed, Mar 8 2006 9:41 AMPermanent Link

Sean McCall
harry,

Table C has no link to table A or B except by date. Is there
a link you forgot to list or is your goal to make sure that
there are only records in C where there at least one record
in B where B.BeginDate <= C.Date <= B.EndDate?

If the latter is the case, I would probably write a
procedure to analyze B to find out what part of the date
range of the deleted B record no longer covered by another
record in B and then delete all the C records within this
range. I am sure there is some nasty select / join statement
that would do this for you, but sometimes FindKey or
SetRange & a little bit of coding is more efficient than SQL.

HTH,

Sean

Harry de Boer wrote:

> LS
>
> table A (Aid)
> table B (Bid, Aid, begindate, enddate)
> table C (Cid, date)
>
> If I delete a record from table A the records in table B where B.Aid=A.Aid
> must also be deleted. No problem. But how do I delete the records in table C
> where C.date BETWEEN  B.begindate AND enddate, but only of course for the
> record(s) where B.Aid=A.Aid
>
> Can this be done in one statement?
>
> Regards, Harry
>
> dbIsam 3.30, D6
>
>
Image