UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Complicated Delete Query, Office 2003    
 
   
skwilliams
post Jun 29 2010, 12:47 PM
Post #1

UtterAccess Veteran
Posts: 326
From: Indiana



I have a linked table (tblProofCycle) that I'd like to run through a query to create a new table.

The table contains the following fields: Order, Desc, dtDate, dtHour, dtMin. The new table (tblProofs) contains the same fields.

Each activity of an order is recorded in the linked table. I'd like to delete all instances of an order if one of it's Description values is "Customer".

Here's an example:

Order DESC DTDATE DTHOUR DTMINUTE
101243769 6/1/2010 6 29
101243769 Customer 6/1/2010 8 1
101243769 6/1/2010 8 1
101243770 6/1/2010 6 32
101243773 6/1/2010 6 35

Using the above example, I need to remove all records for Order 101243769 because one of them contains "Customer".

Can this be done with a delete query?

Thanks.
Go to the top of the page
 
+
jleach
post Jun 29 2010, 12:54 PM
Post #2

UtterAccess Editor
Posts: 6,716
From: Capital District, NY, USA



CODE
DELETE * FROM tblProofCycle WHERE DESC = "Customer"


that will delete any record where DESC is "Customer"

if you want to delete any record that contains "Customer", you can use Like

CODE
DELETE * FROM tblProofCycle WHERE DESC Like "*Customer*"



hth (test on a backup!!! (IMG:style_emoticons/default/thumbup.gif) )
Go to the top of the page
 
+
jleach
post Jun 29 2010, 12:58 PM
Post #3

UtterAccess Editor
Posts: 6,716
From: Capital District, NY, USA



Nevermind... I hate when I reply before I fully understand the question (IMG:style_emoticons/default/crazy.gif)


I think this may be done using a subquery, but unfortunately I don't know how off the type of my head and am not currently in a position to test and find out. Sorry for the bogus reply...
Go to the top of the page
 
+
John Spencer
post Jun 29 2010, 03:14 PM
Post #4

UtterAccess VIP
Posts: 2,445
From: Columbia, Maryland



I would use something like the following. Since ORDER and DESC are reserved words you will probably be forced to surround each field name with square brackets.


STEP 1: BACKUP your data before attempting the following.
STEP 2: BACKUP your data before attempting the following.

Without a backup you cannot restore the data if this does not work the way you expect.

DELETE *
FROM tblProofCycle
WHERE [Order] IN
(SELECT [ORDER]
FROM tblProofCycle
WHERE [DESC] = "Customer")
Go to the top of the page
 
+
skwilliams
post Jul 1 2010, 08:50 AM
Post #5

UtterAccess Veteran
Posts: 326
From: Indiana



That seems to have worked!

Thanks.
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 21st May 2013 - 08:17 PM