Query deleted records in specified table, now doesn't - why?

G

Guest

I'm trying to delete records in Table 1 (Appointments) which are linked to
Table 2 (Leads). So I created a query that says:

DELETE Appointments.*, Appointments.ApptStatus, Leads.Updated, Leads.Source
FROM Appointments INNER JOIN Leads ON Appointments.LeadID = Leads.LeadID
WHERE (((Appointments.ApptStatus)="A" Or (Appointments.ApptStatus)="B" Or
(Appointments.ApptStatus)="C" Or (Appointments.ApptStatus)="D" Or
(Appointments.ApptStatus)="E") AND ((Leads.Updated)>Date()-2) AND
((Leads.Source)="X"));

However, I keep getting an error: Couldn't Delete From Specified Table.

I want this query to remove the records in Table 1 based on the selection
criteria.
 
J

John Spencer

You are attempting to delete from both tables. Remove the references to
Leads fields in the DELETE clause.

I would try the following

DELETE DISTINCTROW Appointments.*
FROM Appointments INNER JOIN Leads ON Appointments.LeadID = Leads.LeadID
WHERE (((Appointments.ApptStatus)="A" Or (Appointments.ApptStatus)="B" Or
(Appointments.ApptStatus)="C" Or (Appointments.ApptStatus)="D" Or
(Appointments.ApptStatus)="E") AND ((Leads.Updated)>Date()-2) AND
((Leads.Source)="X"));

If that fails then post back.
 
M

Marshall Barton

GilesTX said:
I'm trying to delete records in Table 1 (Appointments) which are linked to
Table 2 (Leads). So I created a query that says:

DELETE Appointments.*, Appointments.ApptStatus, Leads.Updated, Leads.Source
FROM Appointments INNER JOIN Leads ON Appointments.LeadID = Leads.LeadID
WHERE (((Appointments.ApptStatus)="A" Or (Appointments.ApptStatus)="B" Or
(Appointments.ApptStatus)="C" Or (Appointments.ApptStatus)="D" Or
(Appointments.ApptStatus)="E") AND ((Leads.Updated)>Date()-2) AND
((Leads.Source)="X"));

However, I keep getting an error: Couldn't Delete From Specified Table.


Don't list fields in the Delete clause:

DELETE Appointments.*
FROM Appointments INNER JOIN Leads
ON Appointments.LeadID = Leads.LeadID
WHERE Appointments.ApptStatus IN("A","B","C","D","E")
AND (Leads.Updated>Date()-2) AND (Leads.Source="X")

BUT, if you were hoping to delete records from both tables,
I don't think that's possible.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top