Connecting Tech Pros Worldwide Forums | Help | Site Map

Help With Delete Query (error)

Needs Regular Fix
 
Join Date: Oct 2007
Location: Hull,UK
Posts: 292
#1: Jul 13 '09
Hello everyone,

i have another task to complete,

i have two tables

Expand|Select|Wrap|Line Numbers
  1. tblEvent
  2. -EventID - PK Auto
  3. -PermaID - FK Num - tblPermavent
  4. -Date - Date
  5. --other irrelevant fields
and......
Expand|Select|Wrap|Line Numbers
  1. tblEventTemp
  2. -TempID - PK Auto
  3. -PermaID - FK Num - tblPermavent
  4. -Date - Date
What i want to do is delete from tblEventTemp when a match between PermaID and Date is found, (if the record exists in tblEvent, delete from tblEventTemp)

so far i have tried this SQL
Expand|Select|Wrap|Line Numbers
  1. DELETE tblEventTemp.* FROM tblEvent INNER JOIN tblEventTemp ON (tblEventTemp.Date = tblEvent.Date) AND (tblEvent.PermaID = tblEventTemp.PermaID);
What i tried to do here is delete * from tblEventTemp and made two joins between the matching fields PermaID and Date.

The query appears to work (in datasheet) however upon execution i get an error "Could not delete from specified tables"

Any Ideas would be most welcome (to resolve my SQL), i figure this would be the easiest and most efficient way of achieving his goal, but if there are better alternatives (that work) they will be welcomes with open arms....

thanks, Dan

Expert
 
Join Date: Jul 2008
Location: Maryland
Posts: 1,176
#2: Jul 13 '09

re: Help With Delete Query (error)


This should work:
Expand|Select|Wrap|Line Numbers
  1. DELETE FROM tblEventTemp 
  2. WHERE EXISTS 
  3. (SELECT EventID FROM tblEvent
  4.  WHERE tblEventTemp.PermaID = tblEvent.PermaID 
  5.  AND tblEventTemp.Date = tblEvent.Date)
You may want to consider renaming the "Date" field!
Needs Regular Fix
 
Join Date: Oct 2007
Location: Hull,UK
Posts: 292
#3: Jul 13 '09

re: Help With Delete Query (error)


Quote:

Originally Posted by ChipR View Post

This should work:

Expand|Select|Wrap|Line Numbers
  1. DELETE FROM tblEventTemp 
  2. WHERE EXISTS 
  3. (SELECT EventID FROM tblEvent
  4.  WHERE tblEventTemp.PermaID = tblEvent.PermaID 
  5.  AND tblEventTemp.Date = tblEvent.Date)
You may want to consider renaming the "Date" field!

Unfortunately it says "query must have at least one destination field"?
Expert
 
Join Date: Jul 2008
Location: Maryland
Posts: 1,176
#4: Jul 13 '09

re: Help With Delete Query (error)


Try DELETE * FROM?
Wierd one.
Needs Regular Fix
 
Join Date: Oct 2007
Location: Hull,UK
Posts: 292
#5: Jul 13 '09

re: Help With Delete Query (error)


that works a treat!!

thanks
Reply


Similar Microsoft Access / VBA bytes