简体   繁体   中英

How can I delete records based on a query?

What I am trying to accomplish is to have VBA run the delete query on backup. The issue is with my query (I hope) I have a select query that isolates records which I want to delete, however when I try to make it a delete query I get this error:

Specify the table containing the records you want to delete.

OR this error:

Reserved error (-3211); there is no message for this error.

My select statement reads:

SELECT Manhours.*, Tickets.Status, Year([Open Date])
FROM Manhours INNER JOIN Tickts ON Manhours.TicketID = Tickets.ID
WHERE (Tickets.Status) = "Closed" AND ((Year([Open Date]))< Year(DATE())-1 
      OR ((Year([Open Date]))= Year(DATE()-1))

The select statement will call the records I need, but when I try to make it a delete query it errors out.

Good news!

I found what I was looking for:

DELETE FROM Manhours WHEN EXISTS (SELECT ID FROM Tickets WHERE (Tickets.Status) = "Closed" AND ((Year([Open Date]))< Year(DATE())-1 OR ((Year([Open Date]))= Year(DATE()-1))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM